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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Complete Ajax Calls Before Submitting Form

Status
Not open for further replies.

robert1964

Programmer
Aug 17, 2010
1
CA
Hello All,

I'm having a serious problem with AJAX in my web application that has our entire development team banging their head against the keyboard.
(Unfortunately, all that banging hasn't yielded a good answer, so I'm hoping one of the experts here have a possible solution!)

The core question is this:
How can I make sure ajax calls to the server have completed?


The problem we're having is that we have a page with a bunch of AJAX calls. The calls work perfectly and the page works well. The issue is that when we submit the form on the page, we get very inconsistent results. Sometimes everything works as expected and we're directed to the correct page. Other times, it seems like the AJAX calls are still

running and when the form is submitted it literally kicks us out of the application.

We tried to increment a counter when we start an ajax call and decrementing it when the ajax call finishes and then only submitting the form if that counter is zero, but that sadly did not work.

Does anyone have any other ideas?

We're also open to using jQuery if that holds the answer.

Any and all help is greatly appreciated. And, if you help and you're ever in the Toronto area, I owe you a bunch of drinks! =)
 
I take you're checking the return values for the calls and they are all correct, rigth? If so, what makes you think the calls are still running? Once the result is sent from the server, it should be over.

Cheers,
Dian
 
Perhaps you could make the form submit button nonfunctional until you have confirmed all the calls are done?
 
[red]How can I make sure ajax calls to the server have completed?[/red]

You could output text to the DOM that reflects returned results from the server. As suggested above, you could change the value property of the submit input item in the same routine that makes the submit input item active.

Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top