Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Example needed for AJAX database update.

Status
Not open for further replies.

theniteowl

Programmer
May 24, 2005
1,975
US
I am looking to have a javascript page make an AJAX request to an ASP page to update a value in a SQL database.
This will be an adiministration page for an intranet web application and I think would work best using AJAX to immediately write each change rather than tracking all changes and submitting at once.

Anyone have sample code for submitting the request to an ASP page and waiting for a response? Perhaps trapping for errors as well as return responses from the page?

I have very little time to work on the application as other tasks are pulling me away but if I find a good example specific to this purpose I should be able to adapt it readily enough.

Thanks.

At my age I still learn something new every day, but I forget two others.
 
I found an example at 15seconds.com

Other than there being a typo in the basic version of the code where it sets the wrong parameter name on the URL it seems to work.

Question though.

On that example in the section where he is testing with readyState, he has not changed the parameter in oXMLHTTP.open to true so it continues processing instead of waiting. Should this be changed?



At my age I still learn something new every day, but I forget two others.
 
It should wait if the 3rd parameter is set to false. If that doesn't work for you, set it to true, and assign a callback function to continue the processing you're after when the readyState indicates a successful call.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Yes, the sample code at that link shows an example of using a callback function and testing the readyState but the writer failed to alter the parameter to true rather than false as I thought it should be.
The first example just waits and so is set false but the second is supposed to be using a callback function and it DOES seem to be working but the parameter is still set false.

So I am either confused on how it is supposed to operate or the parameter really should be set to true and was a mistake in the code.


At my age I still learn something new every day, but I forget two others.
 
Do you want to prevent the user from entering more information until the DB has been updated? or just give them some indication that it's working and when it's finished?

If it is the latter then check this out... faq855-6414
(it uses the .NET 2.0 framework, so might not work for you if your using classic asp).
 
I'm really just interested in determining if the sample code listed above is in error or not so that I know if my understanding of it is correct.

My code is working but it is a very quick query that is executed so I cannot tell if there is an issue with pausing execution or not and it seems that the sample is in error by not setting the true value. If it is not a mistake then I misunderstand how it should work and need clarification.

At my age I still learn something new every day, but I forget two others.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top