new Ajax Request onComplete of every Ajax Request
I'm using Prototype 1.7, what I want is to run a new Ajax Request onComplete of every Ajax Request. But I don't want the Ajax Request run on the 2nd request.
Like this:
AJAX Request Made (Request #1)
+-- Run Request onComplete onComplete of Request #1 (Request #2)+---- Do NOT r开发者_运维问答un request onComplete of Request #2AJAX Request Made (Request #3)
+-- Run Request onComplete of Request #3 (Request #4)+---- Do NOT run request onComplete of Request #4I know I can do this:
Ajax.Responders.register({
onCreate: function() {
},
onComplete: function() {
new Ajax.Request('/update_active.php');
},
onUninitialized: function () {
},
});
The problem is the above creates an endless loop of Ajax Requests.
Anyone have any suggestions on how to accomplish this?
Thanks, -David
You can set a custom option property on the responder-invoked ajax request, and then check for that, before you send the next request:
Ajax.Responders.register({
onComplete: function(transport) {
if( typeof transport.options.isResponder !== 'undefined' ) {
return; // don't start a new request if the custom option is set
};
// set the custom option so this request won't trigger another one
new Ajax.Request('url', {
isResponder: true
});
}
});
You only need to set the option for the responder-triggered request. All other requests can remain unchanged
You can look at the callee of the request and abort if it is coming from itself.
精彩评论