All pastes #182341 Raw Edit

ajax timeout

public javascript v1 · immutable
#182341 ·published 2006-09-25 22:55 UTC
rendered paste body
function getXML(url, doFunc) {	var timeoutId;	var http = getHTTPObject();		http.open("GET", url, true);	http.onreadystatechange = function() {		if (http.readyState == 4) {			if (http.status == 200)			{				window.clearTimeout(timeoutId);				doFunc(http.responseXML);			}		}	}	http.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");	http.send(null);	timeoutId = window.setTimeout(		function() {			switch (http.readyState) {				case 1:				case 2:				case 3:					http.abort();					alert("<?=gettext("Oops. There was an error communicating with the server. Please try again in a few moments.")?>");					errorDoFunc();					break;				default:					break;			}		},		<?=$GLOBALS['ajaxTimeout']?> // twenty seconds	);}