In my usage, Ajax once sent about 50 requests on the same website, making the website unstable, response loss occurs on the platform, but these requests still need to be sent because different systems have passed the Web service value (the customer does not need to cache the requests ), so how can this problem be solved ?? After thinking about the concept of queue, Google searches for jqueue Ajax queue for more information. The following are the results of my filter.
1. ajaxq
Http://plugins.jquery.com/project/ajaxq
$.ajaxq ("testqueue", {
url: "test_1.html",
cache: false,
success: function(html)
{
$("#results").append(html);
}
});
Individual users
Adding a Q and A memory is less relevant to the original usage.
2. ajaxqueue
Http://plugins.jquery.com/project/ajaxqueue
This kit has two methods
// The call cannot be sent to the next request immediately. The next request will be sent only when a request is closed.
Jquery. ajaxqueue ({
URL: "test. php ",
Success: function (HTML) {jquery ("Ul"). append (HTML );}
});
// If a row cannot be automatically uploaded, you must manually modify the row dequeue. I wonder if it is a bug, or does jquery 1.2 allow auto-dynamic queue?
Jquery. dequeue (jquery. ajaxqueue, "ajax ");
// Call the queue immediately, but all events will be shelved. After all requests are closed, all events will be committed (this is not a queue)
Jquery. ajaxsync ({
URL: "test. php ",
Success: function (HTML) {jquery ("Ul"). append ("<B>" + HTML + "</B> ");}
});
Individual users
Only one queue can be created at a time. You still need to manually change the queue.
3. Ajax queue/Cache/abort/block ManagerHttp://plugins.jquery.com/project/AjaxManager
// You need to create ajaxmanager first (directly calling $. manageajax. Add will also be automatically created)
VaR ajaxmanager = $. manageajax. Create ('cachequeue ',{
Queue: True,
Cacheresponse: True
});
Ajaxmanager. Add ({
Success: function (HTML ){
$ ('Ul '). append (' <li> '+ HTML +' </LI> ');
},
URL: 'test.html'
});
// Another method of use
$. Manageajax. Add ('clearqueue ',{
Success: function (HTML ){
$ ('Ul '). append (' <li> '+ HTML +' </LI> ');
},
URL: 'test.html'
});
Individual users
Very difficult to use, do not like
In the end, because there are some pending cases, I don't want to change too much code, but I just want to change a bit, so I started with jquery.
// Rewrite the jquery. Ajax package as self-signed
Jquery. originajax = jquery. Ajax;
Jquery. Ajax = function (option ){
// Because it is not synchronous, I use two queue, one log row, and one log.
VaR oldcomplete = option. Complete;
Option. Complete = function (){
If (oldcomplete) oldcomplete. Apply (this, arguments );
Jquery. dequeue (jquery. Ajax, "ajaxdown ");
};
Jquery ([jquery. Ajax]). Queue ("ajax", function (){
Jquery. originajax (option );
});
Jquery ([jquery. Ajax]). Queue ("ajaxdown", function (){
Jquery. dequeue (jquery. Ajax, "ajax ");
});
VaR q = jquery ([jquery. Ajax]). Queue ("ajaxdown ");
If (Q. Length = 1 ){
Jquery. dequeue (jquery. Ajax, "ajax ");
}
};
Because $. Post and $. Get are called at the end of $. Ajax, I tried $. Ajax to compile the ordered rows. However, there may be gaps.