Synchronize Ajax Requests
I have ajax requests (multiple) coming to my servlet. Each Request is created on the onBlur of the text box. I have a total of 3 such text boxes. I have a requirement that when the response of the firt result comes, then only should the next request be fired. Please let me know if any on开发者_JS百科e has worked on anything like this. I am using Dojo/Digit on client side and simple java Servlet at the server side. Thanks.
You can do this with simple coding. If you need to send the second request only after the response of the first request, you will have to code for the second request in the success condition of your first request. Have a look at the code below:
dojo.xhrPost({
form:"someForm",
load: function(data, args){
// Success
// call the second request
},
error: function(err, args){
// Error
}
});
I hope this helps
You can put an attribute on a node before sending the ajax request. In the call back function you can change the attribute on the node. Before sending any ajax requests you can check this attribute and if already one ajax request is being processed you can avoid sending new request.
It is better to give the user an indication that already one request is being processed.
There is also one attribute called 'sync' http://api.dojotoolkit.org/jsdoc/dojo.xhrGet. But making that to true is not advisable.
精彩评论