Google app engine XMLHttpRequest状态0的哪个回调?
我偶尔会看到XMLHttpRequest.send()失败。从Chrome的网络面板中,我看到状态为0-请参见下面的.har文件。运行send()的代码成功率>99%,但偶尔(~1/300)返回0 我的问题是:我如何抓住这个?有人能抓住它吗 我目前正在使用onload和onerror:Google app engine XMLHttpRequest状态0的哪个回调?,google-app-engine,google-chrome,xmlhttprequest,Google App Engine,Google Chrome,Xmlhttprequest,我偶尔会看到XMLHttpRequest.send()失败。从Chrome的网络面板中,我看到状态为0-请参见下面的.har文件。运行send()的代码成功率>99%,但偶尔(~1/300)返回0 我的问题是:我如何抓住这个?有人能抓住它吗 我目前正在使用onload和onerror: var xhr = new XMLHttpRequest(); xhr.onload = function(){}; xhr.onerror = function(){}; 这两个都没有被调用,所以它默默地失败
var xhr = new XMLHttpRequest();
xhr.onload = function(){};
xhr.onerror = function(){};
这两个都没有被调用,所以它默默地失败了。
还有几件事需要注意:
{
"startedDateTime": "2013-03-30T23:52:20.972Z",
"time": 97,
"request": {
"method": "GET",
"url": "https://www.#######.com/project/auth_upload?to_sign=PUT%0A%0A%0A%0Ax-amz-date%3ASat%2C%2030%20Mar%202013%2023%3A52%3A20%20GMT%0A/s3.#####.com/######.mp4%3FpartNumber%3D50%26uploadId%3D#################.w--&asset_id=#############&project_id=###########",
"httpVersion": "HTTP/1.1",
"headers": [
{
"name": "Referer",
"value": "https://www.######.com/console/###########"
},
{
"name": "User-Agent",
"value": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.152 Safari/537.22"
}
],
"queryString": [
{
"name": "to_sign",
"value": "PUT%0A%0A%0A%0Ax-amz-date%3ASat%2C%2030%20Mar%202013%2023%3A52%3A20%20GMT%0A/s3.#######.com/############.mp4%3FpartNumber%3D50%26uploadId%3D##############"
},
{
"name": "asset_id",
"value": "###########"
},
{
"name": "project_id",
"value": "###############"
}
],
"cookies": [],
"headersSize": 595,
"bodySize": 0
},
"response": {
"status": 0,
"statusText": "",
"httpVersion": "HTTP/1.1",
"headers": [],
"cookies": [],
"content": {
"size": 0,
"compression": 0
},
"redirectURL": "",
"headersSize": 13,
"bodySize": 0
},
"cache": {},
"timings": {
"blocked": 0,
"dns": -1,
"connect": -1,
"send": -1,
"wait": -1,
"receive": null,
"ssl": -1
}
}
谢谢
tom看来状态码0表示响应是空的,即使没有发送头,这是很难理解的,您需要自己找到它 但是您说响应没有到达函数中是因为您正在使用
load
和error
事件来侦听响应,实际上您不应该完全依赖这两个错误,考虑到超时在请求完成之前发生的情况,那么“超时”事件将被触发而不是“错误”< /P>
相反,您应该使用readystatechange
事件,该事件将在请求的每个状态更改时调用,并且您还可以跟踪与未收到响应相关的超时或错误
httpRequest.onreadystatechange = stateChangeHandler;
stateChangeHandler = function() {
// The readyState can be 4 values:
// 0 - uninitialized
// 1 - loading
// 2 - loaded
// 3 - interactive
// 4 - complete
//
// readyState 0 - 3 can be completely ignored by us, as they are only updates
// about the current progress. Only on readyState 4, should we continue and
// start checking for the response status.
if (xmlHttpRequest.readyState != 4) {
return;
}
// Check HTTP Response code
if (xmlHttpRequest.status != 200) {
// response is ok process it
} else {
// there was some error
}
}
参考资料:
谢谢我将尝试一下,然后我将报告它是否捕捉到了我的错误。对它进行了测试,它成功了。ReadyState==4 status==0确实捕捉到了这种情况。值得注意的是,Chrome开发工具网络面板将状态报告为“(已取消)”