2013-03-26 61 views
0

这里是我的代码:原型的Ajax.Updater更新之前评估串

new Ajax.Updater('container', url, { 
    method: "get", 
    onLoading: function() { 
     document.getElementById('container').innerHTML = "Loading..."; 
    }, 
    on200: function(response) { 
     if(response.responseText.match(/WhatImLookingFor/)) { 
      window.location = "leNewURL"; 
     } 
    }, 
    onComplete: function(response) { 
     //do other cool stuff 
    } 
}); 

我试图做的是拦截container前的响应更新,并且如果在响应中的文本相匹配WhatImLookingFor,我想将用户重定向到leNewURL。随着上面的代码正在发生,但不是更新之前,所以它看起来古怪。无论如何,我可以在更新发生之前拦截,或者我不得不求助于其他黑客,比如隐藏container,只有在没有匹配的情况下才显示它。

回答

1

如果你想自定义你的Ajax调用的行为一样,我会建议使用基本Ajax.Request()http://api.prototypejs.org/ajax/Ajax/Request/

new Ajax.Request(url, { 
    method: "get", 
    onLoading: function() { 
     $('container').update("Loading..."); 
    }, 
    onComplete: function(response) { 
     if(response.responseText.match(/WhatImLookingFor/)) { 
      window.location = "leNewURL"; 
     } 
     else { 
      //do other cool stuff 
      $('container').update(response.responseText); 
     } 
    } 
}); 

我换出document.getElementById()$()实用方法,它的打字比较少,包括所有PrototypeJS的元素方法

+0

我怀疑这是我所要做的,但希望有钩子在那里...无论哪种方式,谢谢 – rantsh 2013-03-27 13:29:22