Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem seems to be that <a href="http://www.w3.org/TR/XMLHttpRequest/#the-timeout-attribute" rel="nofollow"><code>timeout</code></a> and <code>ontimeout</code> aren't yet part of some implementations:</p> <pre><code>var hasTimeout = 'timeout' in new XMLHttpRequest(); // false </code></pre> <p>At least, it's not in Chrome 16 or Firefox 7. And, this should return <code>true</code> given the requirements:</p> <blockquote> <p>The <code>timeout</code> attribute must return its value. Initially its value must be zero.</p> </blockquote> <p>Both have been part of the <a href="http://www.w3.org/TR/XMLHttpRequest/" rel="nofollow">XHR 2 spec</a> since <a href="http://www.w3.org/TR/2010/WD-XMLHttpRequest2-20100907/" rel="nofollow">Sept 7, 2010</a>. But, as the "Level 2" spec has been been around since <a href="http://www.w3.org/TR/2008/WD-XMLHttpRequest2-20080225/" rel="nofollow">Feb 25, 2008</a> and is still a "Working Draft," there's not really a guarantee that any implementation would be up-to-date with the spec.</p> <hr> <p>Without those available to you, you can try instead using <code>onabort</code> and <code>setTimeout</code> (as you stated in your comment):</p> <pre><code>// snip to = function() { attempt++; if( attempt &lt; 5) send(); else if( !silent) { console.log("Request Timeout\nFailed to access "+url); } }; // snip var send = function() { if( loader &amp;&amp; attempt != 0) { loader.children[0].firstChild.nodeValue = "Error... retrying..."; loader.children[1].firstChild.nodeValue = "Attempt "+(attempt+1)+" of 5"; } a = new XMLHttpRequest(); a.open("POST","/ajax/"+url,true); a.onreadystatechange = rsc; setTimeout(function () { /* vs. a.timeout */ if (a.readyState &lt; 4) { a.abort(); } }, 5000); a.onabort = to; /* vs. a.ontimeout */ a.setRequestHeader("Content-Type","application/json"); a.send(data); console.log('HTTP Requesting: %s', url); }; // snip </code></pre> <p>Example: <a href="http://jsfiddle.net/AmQGM/2/" rel="nofollow">http://jsfiddle.net/AmQGM/2/</a> -- The <code>?delay=2</code> should finish, while the <code>?delay=10</code> expires its 5 tries.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload