File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes [Jquery 1.2.6] Response mismatch with multiple ajax requests in a row Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "[Jquery 1.2.6] Response mismatch with multiple ajax requests in a row" Watch "[Jquery 1.2.6] Response mismatch with multiple ajax requests in a row" New topic
Author

[Jquery 1.2.6] Response mismatch with multiple ajax requests in a row

Emilio Meadow
Greenhorn

Joined: Jul 20, 2009
Posts: 14
Hi,

I'm pretty new with jquery and not very skilled with javascript either.
I have a function that handles a onClick event.
This function makes 3 ajax requests "in a row", here is the (psedo-)code:



What happens sometimes is that the response "secondData" of the second call appears either in the "#firstId" element and in the "#secondId" element or in the "#thirdId" element and in the "#secondId" element.
I solved temporarly the problem by nesting the three requests and the problem seems to be solved. But this, of course, is only a work around...
Any hint?

Cheers

Emilio


- we all get it in the end -
Bear Bibeault
Author and opinionated walrus
Marshal

Joined: Jan 10, 2002
Posts: 50691

I don't see how that could possibly happen, but why are you using such an old version of jQuery? You really should be using the most modern version.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Bear Bibeault
Author and opinionated walrus
Marshal

Joined: Jan 10, 2002
Posts: 50691

And, why aren't you using the .load() method rather than the low-level $.ajax() function?
Jee Ba
Greenhorn

Joined: Feb 08, 2011
Posts: 7
Well its not really a problem, thats what the first "A" in Ajax means = "Asyncronous", that's mean that when you send, for example, 2 ajax calls, the response will come unordered. Nesting them is a good option with few calls, I remember that there was a library on jquery 1.2.6 that could chain Ajax request. But new version of Jquery comes with better handling of Ajax. Look for something like jquery ajax chain in google
Bear Bibeault
Author and opinionated walrus
Marshal

Joined: Jan 10, 2002
Posts: 50691

There is no need to chain the calls. None.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15003
It is a race condition on what call comes back first. Just because the first one was called first does not mean it will come back first.

First question is why not make one call that can return all three parts at once. Saves your server from being bombarded with calls.

If you have to make 3 calls, look into jQuery queue. Nice explanation here. Scroll down the post a bit for an Ajax example.

Eric
Bear Bibeault
Author and opinionated walrus
Marshal

Joined: Jan 10, 2002
Posts: 50691

As each request has its own success callback, there should be no need to chain or queue unless order matters. It doesn't look like order matters in this case.
 
 
subject: [Jquery 1.2.6] Response mismatch with multiple ajax requests in a row
 
Threads others viewed
For Servlet request, FireFox is opening file for JSON Data
Replace current html page with ajax response
Jquery ajax issue
Success function of jquery ajax do not run. Whats the problem?
Submit dynamically created form with jQuery
IntelliJ Java IDE