可以原型或JQuery的返回一个HTTP状态code对一个AJAX请求 [英] Can Prototype or JQuery return an HTTP status code on an AJAX request
问题描述
url = "http://example.com"
new Ajax.Request(url, {
onComplete: function(transport) {
alert(transport.status);
}
});
我想,要返回200状态,如果该网站的工作,或500,如果它不能正常工作,等等。但是,code将返回0所有的时间。
I'd like that to return a status of 200 if the site is working, or 500 if it is not working, etc.. But that code is returning 0 all the time.
最后,我想有一个setInterval函数,定期坪的正常运行状态的一个网站。
Ultimately, I want to have a setinterval function that regularly pings a website for uptime status.
推荐答案
使用jQuery,你应该得到一个code相似,你有你的地位,这将是这样的:
With JQuery you should get your status with a code similar to what you have, and it will be something like this:
$.ajax({
url: 'some.url.com',
type: 'POST',
complete: function(transport) {
if(transport.status == 200) {
alert('Success');
} else {
alert('Failed');
}
}
});
如果你想用你的原型code应该只补充一点:
And if you want to use prototype your code should only add this:
onXYZ:function(transport){
}
在上面XYZ文本应当由你想赶上了响应HTTP状态code来代替。
In the text above XYZ should be replaced by the http status code you want to catch for the response.
希望这有助于
这篇关于可以原型或JQuery的返回一个HTTP状态code对一个AJAX请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!