ajax request timeout
How can i track ajax call time out in the following simple ajax function
function process()
{
document.getElementById('message').innerHTML='Loading..';
var ajaxRequest; // The variable that makes Ajax possible
try
{
ajaxRequest = new XMLHttpRequest();
}
catch (e)
{
try
{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
ajaxRequest.onreadystatechange = function()
{
if(ajaxRequest.readyState == 4)
{
var ajaxDisplay = document.getElementById('message');
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}
var query;
query="process.php?action开发者_StackOverflow中文版=delete";
ajaxRequest.open("POST", query, true);
ajaxRequest.send(null);
}
Try this:
function process()
{
document.getElementById('message').innerHTML='Loading..';
var ajaxRequest; // The variable that makes Ajax possible
try
{
ajaxRequest = new XMLHttpRequest();
}
catch (e)
{
try
{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
ajaxRequest.onreadystatechange = function()
{
if(ajaxRequest.readyState == 4)
{
//Ajax successful, we don't need to abort it anymore...
clearTimeOut(AjaxTimeOut);
var ajaxDisplay = document.getElementById('message');
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}
var query;
query="process.php?action=delete";
ajaxRequest.open("POST", query, true);
ajaxRequest.send(null);
//Set when to abort ajax request...
var AjaxTimeOut = setTimeOut("function(){ajaxRequest.abort};", 60000);
}
精彩评论