0

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

Harish Kurup
  • 7,257
  • 19
  • 65
  • 94

2 Answers2

0

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.

Delan Azabani
  • 79,602
  • 28
  • 170
  • 210
0

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?

baloo
  • 7,635
  • 4
  • 27
  • 35