Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Jun 2010
    Posts
    290
    Thanks
    63
    Thanked 8 Times in 8 Posts

    Setting AJAX timeout has no effect in IE 9.0

    Briefly, I have a page that does the following:

    1) User types the URL of a website into a text box and hits enter.

    2) AJAX request to PHP script which tries to open the URL using cURL to see if the URL is broken or not.

    3) Response sent to browser, picked up by AJAX and message displayed on screen.

    The cURL timeout is set to 10 seconds - I think that's a reasonable time to expect a response from a remote server.

    I've tested this code in FF, Opera, Chrome, Iceweasle and Safari and it works fine in all those.

    But in IE 9 ... it doesn't work! (Surprise!!!! Good old IE, always screwing things up).

    So I dug into the code a little and the problem surfaces here:

    Code:
    //ajax is an instance of an ActiveXObject.
    
    if (ajax.readyState == 4)
      {
        if (ajax.status == 200)
          {
            if (userfunc != 0)
              userfunc(tw_getJsonObjects(ajax.responseText));
          }
        else
         {
           alert("An error has occured making the request: " + ajax.status);
         }
      }
    Sure enough, in IE (and only in IE), I get an alert box which shows the ajax status to be 12002.

    12002 turns out to be ERROR_INTERNET_TIMEOUT (See here: http://forums.codeguru.com/showthrea...72#post1623372)

    So, I had another rummage in Google, and I found this: http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx

    In that microsoft link, it clearly states, "With the timeout property, Web developers can specify the length of time in milliseconds for the host to wait for a response before timing out the connection". It actually says that on Microsoft's own website, so it must be true ... but apparently not ... read on ...

    I have implemented the timeout precisely as described in that document, except I have given it a value of 20000 milliseconds.

    And the result is .... (drumroll) ... it has no effect whatsoever. The request times out after 10 seconds as before.

    I can implement an AJAX poll once every 5 seconds, but this seems complete overkill for a problem which Microsoft themselves say is easy to fix with a single line of code!!! Only it doesn't work on my browser ...

    Any ideas?
    Last edited by XmisterIS; 11-07-2013 at 10:49 AM.

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,033
    Thanks
    0
    Thanked 249 Times in 245 Posts
    Is your ajax request asynchronous or not? Timeout does not apply on synchronous requests. Can you post more code?

  • #3
    Regular Coder
    Join Date
    Jun 2010
    Posts
    290
    Thanks
    63
    Thanked 8 Times in 8 Posts
    The request is asynchronous, I'm calling send with the third parameter set to TRUE.

    Perhaps if I wrap a synchronous call to send in an anonymous function passed to setTimeout that might get round the problem.

    What other code would you like to see? There's a fair bit ...

  • #4
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,277
    Thanks
    10
    Thanked 581 Times in 562 Posts
    Quote Originally Posted by XmisterIS View Post
    I have implemented the timeout precisely as described in that document, except I have given it a value of 20000 milliseconds.

    And the result is .... (drumroll) ... it has no effect whatsoever. The request times out after 10 seconds as before.
    since 10000 milliseconds is fewer than 20000 milliseconds, it would break the laws of physics if a 20000 ms timeout had any effect on something that was over with in ten seconds...
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #5
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,593
    Thanks
    0
    Thanked 645 Times in 635 Posts
    The comments say you are using an activeXObject in IE for the Ajax call - that was needed for IE4 through IE6 but IE8 and later have used the same code as other browsers.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #6
    Regular Coder
    Join Date
    Jun 2010
    Posts
    290
    Thanks
    63
    Thanked 8 Times in 8 Posts
    Quote Originally Posted by rnd me View Post
    since 10000 milliseconds is fewer than 20000 milliseconds, it would break the laws of physics if a 20000 ms timeout had any effect on something that was over with in ten seconds...
    No. The timeout occurs after 10 seconds. The cURL timeout is 10 seconds. The slight overhead associated with running the rest of the script, and performing the AJAX calls pushes the TX/RX time slightly above 10 seconds, hence the timeout. By setting the timeout to 20 seconds, no timeout should occur.

    Quote Originally Posted by felgall View Post
    The comments say you are using an activeXObject in IE for the Ajax call - that was needed for IE4 through IE6 but IE8 and later have used the same code as other browsers.
    That is interesting! I will try that. I think I probably still need to support IE6 and earlier, I can conceive of a couple of ways to get round the problem (the simplest one I can think of is to poll for a flag which PHP raises in $_SESSION when the script completes). I wonder how many clunky old machines are still using IE6. (Reminds me of some old engineers I use to work with, who insisted that there is nothing that can't be done in Fortran 77 on a VAX, and that there's no need for these new-fangled desktop computers ... )
    Last edited by XmisterIS; 11-08-2013 at 09:17 AM.

  • #7
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,593
    Thanks
    0
    Thanked 645 Times in 635 Posts
    Quote Originally Posted by XmisterIS View Post
    That is interesting! I will try that. I think I probably still need to support IE6 and earlier, I can conceive of a couple of ways to get round the problem (the simplest one I can think of is to poll for a flag which PHP raises in $_SESSION when the script completes). I wonder how many clunky old machines are still using IE6.
    Most web sites dropped support for IE6 several years ago when the number of users fell low enough for them to decide to ignore all the complexities that antiquated browser presented. Many web sites have now dropped support for IE7 as well and it may soon be possible to ignore any of the IE9 only issues as the number of people using that browser is now also rapidly falling.

    Most IE users are now using either IE8 or IE10 and the IE10 users are expected to gradually shift across to IE11.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #8
    Regular Coder
    Join Date
    Jun 2010
    Posts
    290
    Thanks
    63
    Thanked 8 Times in 8 Posts
    That is interesting ... that IE9 is pretty much ignored.

    Mind you, I have fixed the issue by way of a very simple work-around: I just buffer the AJAX response in $_SESSION, then poll the server for the contents of the buffer each time the AJAX request times out. It's a very neat and simple solution!


  •  

    Posting Permissions

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