JavaScript Phrasebook
Depending on the browser, only a limited number of HTTP requests can be done at a time. Especially if you have a page with multiple AJAX components (the modern term for this is "mashup"), you may run into trouble. Therefore, aborting an HTTP request may become a necessity. The method used for that is abort(). The following code aborts the request if it has not been fully executed after five seconds. To demonstrate this behavior, the PHP script delay.php that is called by the code takes 10 seconds to execute. Also note that the readyState property is checked first: if it is 0 or 4, there is nothing to abort. Aborting an HTTP Request (xmlhttpabort.html)
Five seconds after loading this page, the request is aborted. Tip Appending the result of Math.random() to the URL to call causes caching for the script delay.php to be disabled, since the URL is a different one every time.
|
Категории