SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jun 2006
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    post request in ie taking forever

    simplified code is below. ive left just the http request function. i've checked it against a number of tutorials and can't find anything wrong with the code. what it should do is count to 4 in alert boxes for the onreadystatechange. in firefox, it happens as quickly as you'd expect. but in ie it get's to 3 and stalls. it takes minutes to get to 4. ive tried it on more than one host, so i dont think it's a server issue. i'm thinking maybe it's a header issue? code is running here - feel free to try it.

    http://www.textgoeshere.com/test.asp#

    any ideas?

    thanks,

    corey

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    </head>
    <script type="text/javascript">
    function makePOSTRequest() {
    if (window.XMLHttpRequest) { // Mozilla, Safari,...
    http_request = new XMLHttpRequest();
    if (http_request.overrideMimeType) {
    http_request.overrideMimeType('text/xml');
    }
    } else if (window.ActiveXObject) { // IE
    try {
    http_request = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
    try {
    http_request = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (e) {}
    }
    }
    if (!http_request) {
    updateHint("Cannot create XMLHTTP instance");
    return false;
    } else {
    return http_request;
    }
    }

    function test() {
    var updateString='';
    http_request=makePOSTRequest();
    http_request.open('POST', "/test.response.asp", true);
    http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http_request.setRequestHeader("Content-length", updateString.length);
    http_request.setRequestHeader("Connection", "close");
    http_request.send(updateString);
    http_request.onreadystatechange = function() {
    alert(http_request.readyState);
    if (http_request.readyState == 4) {
    if (http_request.status == 200) {
    }
    }
    }

    }
    </script>

    </head>

    <body>
    <a href="#" onclick="test();">test</a>
    </body>
    </html>

  2. #2
    SitePoint Enthusiast Sjoerd's Avatar
    Join Date
    Jun 2005
    Location
    Leimuiden, The Netherlands
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When I click at your link, I get three window.alerts which state "2", "3" and "4", so it seems to be working pretty fast over here. I tried with Firefox, Internet Explorer and Opera 8 and 9. Opera did seem to skip the state "2", but that shouldn't matter for the results.

  3. #3
    SitePoint Enthusiast Sjoerd's Avatar
    Join Date
    Jun 2005
    Location
    Leimuiden, The Netherlands
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    By the way, I think you're better of by replacing:

    Code:
    http_request=makePOSTRequest();
    With

    Code:
    http_request=new makePOSTRequest();
    Otherwise, if you use two XMLHTTP calls at the same time, the second one will clear out and stop the first one.

  4. #4
    SitePoint Member
    Join Date
    Jun 2006
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thx, good point about the multipe requests.

    maybe it's just my machine? i'll try it on a few others. one other possible solution i found is that my returned document is content-type text/html despite the content being xml. and i've found a few mentions of ie freaking out over that. something else to try.

    thanks!

    corey


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •