开发者

Why AJAX sometimes send two same requests

I'm working with AJAX for long time, and it sometimes send one request, and then like it's mistake it send another one, second request get respond, but first one keeps loading to infinite ( on FireBug ), and code that catches responses isn't trigger... It's good when you sending request, it's processed by other side, but when you are getting data from it, it doesn't work all the time...

Here is开发者_开发问答 code:

function ajaxF(urlr,obradi, data)
{
var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
        if ( first != 1 )
            {
                alert("Your browser does not support AJAX!");
                return false;
            }
       }
    }
  }

  xmlHttp.onreadystatechange=function()
    {
     if (xmlHttp.readyState == 4)
{
      if (xmlHttp.status == 200)
        {

        if ( xmlHttp.responseText != '' )
                {


                if ( obradi == 'dosomething' )
                {
                //do something
                }




                }

          }
}

    }

  xmlHttp.open("POST",urlr,true);
  xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  xmlHttp.setRequestHeader("Content-length", data.length);
  xmlHttp.setRequestHeader("Connection", "close");
  xmlHttp.send(data);


}




data = 'value=1';
ajaxF("file.php", "dosomething",data);


I dont have the answer to your problem, But have you tried using a framework for the ajax requests, like JQuery or Prototype? Both are very simple to use and and dont seem to get these errors, as they have been fine tuned.

Sorry if this isn't any help.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜