开发者

Problem with Ajax submission?

开发者 https://www.devze.com 2023-01-01 16:04 出处:网络
I am using Ajax to post data to the server(PHP code) and update it. i am posting many data one after the other, but in between the Ajax post fails and dont return a readyState to 4.

I am using Ajax to post data to the server(PHP code) and update it. i am posting many data one after the other, but in between the Ajax post fails and dont return a readyState to 4. the code is as follows

function getHttpRequest()
{
   var request=false;
   if(window.XMLHttpRequest)
   {
       request=new XMLHttpRequest();
   }
   else if(window.ActiveXObject)
   {
       try
       {
           request=new 开发者_如何转开发ActiveXObject("Msxml2.XMLHTTP");
       }
       catch(e)
       {
           try
           {
               request=new ActiveXObject("Microsoft.XMLHTTP");
           }
           catch(e)
           {
               request=false;
           }
       }
   }

   return request;
}

the code begins here..

function updateAnswer(){
var request=getHttpRequest();
request.open('post','addAnswer.php');
request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
request.send("answer="+ans);

if(request.readyState == 4)
{
    var response=request.responseText;
    document.getElementById("display").innerHTML=response;
}
}

i call this function to update answer in database but it donot return status=4 sometimes... please help


innerinnerHTML should be innerHTML. updateAnswer gets called each time readyState is changing from zero to four. Four is fully loaded, while those lesser are different loading stages.


Why not make life easier and use a framework like jQuery?

Also, can't you post all the data at once, in that way save a few roundtrips to the server?

0

精彩评论

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

关注公众号