我正在从https页面向https页面提交Ajax请求。在所有其他浏览器中,这会立即显示,但在Chrome中它会挂起很长时间(通常约为40秒)。
可能导致这种情况的原因是什么?我该如何解决?
示例JQUERY CODE也导致悬挂
<html>
<head>
<script type="text/javascript" src="jquery-1-9-1.js"></script>
</head>
<body>
<br/>
<a onclick="doit()">go</a>
<script>
function doit()
{
var myData = { "key": "value" };
$.ajax({
url: "myhandlepage.php",
data: myData,
dataType: 'json',
type: 'POST',
contentType: 'application/x-www-form-urlencoded',
success: function (data) { alert("OK = " + data.eric); },
error: function (data, status) { alert("FAILED:" + status); }
});
}
</script>
</body>
</html>
示例代码
//Create browser-compliant request object
if( typeof XMLHttpRequest === "undefined" ) XMLHttpRequest = function()
{
try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); } catch(e) {}
try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); } catch(e) {}
try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {}
try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {}
throw new Error( "This browser does not support XMLHttpRequest." );
};
//Create object
var ajax = new XMLHttpRequest();
//We need to open the object
ajax.open( "post", "/myhandlepage.php", true );
//Now set the callback
ajax.onreadystatechange = function()
{
//elided, but doesn't matter, I can see the 40+ second delay in chrome developer tools
}.bind( this );
//Send the request
ajax.send( mycontent );
澄清:Chrome的开发者工具中没有显示任何错误。
编辑:此问题似乎仅发生在Chrome中标签/页面的第一次请求中。在第一个滞后请求之后,同一个标签/页面中的所有ajax请求似乎都会立即通过。
更多信息 仅在挂起请求中查看chrome:net-internals /#events,在所有请求的中间,我看到:
t=1360622033867 [st= 4] HTTP_STREAM_PARSER_READ_HEADERS [dt=38643]
--> net_error = -100 (ERR_CONNECTION_CLOSED)
然后它再次发送整个请求,第二次立即通过。什么可能导致第一次失败的请求?每次我打开浏览器后第一次向该URL发出请求时都会发生这种情况。