Javascript 原型Ajax.Updater在更新之前评估字符串
这是我的密码:Javascript 原型Ajax.Updater在更新之前评估字符串,javascript,ajax,prototypejs,Javascript,Ajax,Prototypejs,这是我的密码: new Ajax.Updater('container', url, { method: "get", onLoading: function () { document.getElementById('container').innerHTML = "Loading..."; }, on200: function(response) { if(response.responseText.match(/WhatImL
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
}
});
我试图做的是在
容器
更新之前拦截响应,如果响应中的文本与WhatImLookingFor
匹配,我想将用户重定向到leNewURL
。在上面的代码中,这种情况正在发生,但不是在更新之前,所以看起来很奇怪。在更新发生之前,我是否可以截取任何东西,或者我是否必须求助于其他黑客,比如隐藏容器,并仅在没有匹配时才显示它?如果您想像这样自定义Ajax调用的行为,我建议使用基本的Ajax.Request()
我用$()
实用程序方法替换了文档.getElementById()
,因为它的类型较少,并且包含了PrototypeJS的所有元素方法我怀疑这是我必须要做的,但希望有一个钩子在那里。。。不管怎样,谢谢
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);
}
}
});