|
Project Information
Featured
Downloads
Links
|
AjaxQ is a jQuery plugin that implements AJAX request queueing mechanism. Why?There are several reasons why you may need to queue AJAX requests and run them in a sequential manner:
How?Assume that the web application has to make two AJAX requests. Here's the usual and the simplest way of doing it: $.ajax ({
url: "test_1.html",
cache: false,
success: function(html)
{
$("#results").append(html);
}
});
$.ajax ({
url: "test_2.html",
cache: false,
success: function(html)
{
$("#results").append(html);
}
});The requests will run almost simultaneously. Moreover, the response to the second request may come first. Let's look at how to use AjaxQ plugin, and make the requests run in a sequential manner: $.ajaxq ("testqueue", {
url: "test_1.html",
cache: false,
success: function(html)
{
$("#results").append(html);
}
});
$.ajaxq ("testqueue", {
url: "test_2.html",
cache: false,
success: function(html)
{
$("#results").append(html);
}
});Now the first requests runs first, and the second request runs only when the first one finishes. There are only two essential differences between these two code blocks:
NotesThe number of AJAX queues is not limited. Web application may have as much AJAX queues as it requires. However, consider the limit of browser connections in case you have two or more queues running at the same time. API$.ajaxq (queue, options) Enqueues a new AJAX request.
$.ajaxq (queue) Stops the current AJAX request and clears the queue.
|