9

I have an app that sends multiple Ajax requests simultaneously. I was originally running into race conditions until I discovered the jQuery Ajax Queue plugin, which works great with jQuery 1.2, but fails with jQuery 1.3. There are actually two different versions of the plugin; I am currently using this one which is the same as the first but just adds a bit more functionality.

Anyway, I am using Firebug on Firefox 3.0.10 and when I run my code I don't receive any explicit errors, the call is just never returned.

I could obviously continue using v1.2 but would really like to learn why this plugin fails with the latest release and what I can do to get it working.

Thanks in advance.

J.C. Yamokoski
  • 1,014
  • 9
  • 23

3 Answers3

14

You should be able to use jQuery's built-in queue support if you're willing to do a bit of legwork.

// First Ajax request
$(document).queue("ajaxRequests", function() {
  $.ajax({
    // Stuff
    success: function() {
      $(document).dequeue("myName");
    });
  });
});

// Second Ajax request
$(document).queue("ajaxRequests", function() {
  $.ajax({
    // Stuff
    success: function() {
      $(document).dequeue("myName");
    });
  });
});

// Trigger the queue
$(document).dequeue("ajaxRequests");

Of course, it would be pretty easy to wrap that in a plugin.

Yehuda Katz
  • 28,535
  • 12
  • 89
  • 91
  • I just discovered this answer via Google. This worked amazing for my site. Thanks! – gen_Eric Dec 16 '10 at 22:38
  • Also a keeping a flag with the document element with data() helps when you want to keep track of requests made and when to queue the requests – Kapil Dec 18 '10 at 12:36
  • 3
    why is the name passed to dequeue "myName" different from the value used in queuing them up "ajaxRequests"? Shouldn't they be the same (name of the queue)? – Anony372 Jul 07 '11 at 23:08
  • will that work? It will send the ajax requests one after the other, but they are asynchronous - they will both fired, rather than queued. – Bozho Feb 23 '12 at 21:53
3

Just found the answer to this looking for a solution myself. Someone decided to modify the original ajaxQueue plugin.

http://www.onemoretake.com/2009/10/11/ajaxqueue-and-jquery-1-3/

Ryan
  • 31
  • 1
0

ajaxManager plugin is based on the Ajax Queue Plugin but is a bit more flexible and works with jQuery 1.3.2.

Sam Hasler
  • 12,344
  • 10
  • 72
  • 106