1

I'm submitting an Ajax request from an https page to an https page. In all other browsers, this goes through instantly, but in Chrome it hangs for a long time (usually about 40 seconds).

What could be causing this? how do I fix it?

EXAMPLE JQUERY CODE THAT ALSO CAUSES THE HANG

<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>

EXAMPLE CODE

//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 );

For clarification: no errors are shown in Chrome's developer tools.

EDIT: It appears that this issue only happens on the first request for a tab/page in Chrome. All ajax requests in that same tab/page seem to go through instantly after the first lagging request.

MORE INFO Looking in chrome:net-internals/#events on the hanging request only, in the middle of all the requests, I see this:

t=1360622033867 [st=    4]        HTTP_STREAM_PARSER_READ_HEADERS  [dt=38643]
                              --> net_error = -100 (ERR_CONNECTION_CLOSED)

Then it sends the entire request again, and that second time it goes through instantly. What could be causing this first failed request? It occurs every time I do the request for the first time to that URL since opening the browser.

14
  • why don't you just use jQuery.ajax() ?
    – user1386320
    Feb 11, 2013 at 22:14
  • jQuery ajax is exactly the same code underneath. My example code is the exact code that a browser sees when ajax is called.
    – Don Rhummy
    Feb 11, 2013 at 22:17
  • Could you try with jQuery.ajax()? I'm not saying you should use it, I just want to see whether your backend hangs with Chrome+jQuery. If it does, the problem is not with your JavaScript code, but with the backend logic.
    – tompave
    Feb 11, 2013 at 22:18
  • Also, have you looked at the request HTTP headers? Is Chrome adding something funny?
    – tompave
    Feb 11, 2013 at 22:20
  • @wonderingtomato I'll try jquery. Give me a few minutes and I'll report back. Also: where can I view the headers being sent across by chrome?
    – Don Rhummy
    Feb 11, 2013 at 22:22

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.