Ajax请求超时



如何在以下简单的ajax函数中跟踪ajax调用超时

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=delete";
    ajaxRequest.open("POST", query, true);
    ajaxRequest.send(null);
}

试试这个:

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);
}

相关内容

  • 没有找到相关文章

最新更新