2011-08-10 90 views
1

我正在使用Prototype 1.7,我想要的是运行一个新的Ajax请求onComplete每个Ajax请求。但我不希望Ajax请求在第二个请求上运行。新Ajax请求onComplete每个Ajax请求

像这样:

AJAX请求提出(请求#1)
+ - 的请求#1(请求#2)
+ ----不运行的请求#请求的onComplete运行请求的onComplete的onComplete 2

AJAX请求提出(请求#3)
+ - 运行请求的请求#3的onComplete(请求#4)
+ ----不运行的请求#请求的onComplete 4

我知道我可以这样做:

Ajax.Responders.register({ 
         onCreate: function() { 
         }, 
         onComplete: function() { 
          new Ajax.Request('/update_active.php'); 
         }, 
         onUninitialized: function() { 
         }, 
         }); 

问题在于上述情况会创建无限循环的Ajax请求。

任何人有任何建议如何做到这一点?

感谢, -David

回答

1

您可以设置在响应程序调用Ajax请求的自定义选项属性,然后检查,你发送下一个请求之前:

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 
     }); 
    } 
}); 

你只需要设置为responder-选项触发请求。所有其他请求可以保持不变

+0

非常好!非常感谢你! – dcmoody

0

你可以看一下请求的callee和中止如果从自身的到来。