This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

timeout

Summary

Returns or sets the number of milliseconds a request can take before automatically being terminated.

Property of apis/xhr/XMLHttpRequestapis/xhr/XMLHttpRequest

Syntax

var result = element.timeout;
element.timeout = value;

Return Value

Returns an object of type unsigned longunsigned long

Examples

// The following example sets the timeout property

var xhr = new XMLHttpRequest();
xhr.open("GET", "http://localhost/books.xml", true);
xhr.timeout = 10000;
xhr.ontimeout = timeoutFired;
xhr.send(null);

Notes

The timeout property has a default value of 0. If the time-out period expires, the responseText property will be null. You should set a time-out value that is slightly longer than the expected response time of the request. The timeout property may be set only in the time interval between a call to the open method and the first call to the send method. If you set an XMLHttpRequest time-out value that is larger than the network stack’s time-out value, the network stack will time out first and the ontimeout event will not be raised.

Related specifications

W3C XMLHttpRequest Specification
W3C Working Draft

Attributions