ajax - onreadystatechange events

the ajax - onreadystatechange event is triggered every time the readystate changes.event handlers are called as needed after a request is sent.

the ajax onreadystatechange event syntax :-

            new xmlhttprequest().onreadystatechange  = handler ;

ajax - onreadystatechange event example :-

     <script>
            
          function statushandler() {
                 
   if  ( requestobject.readystate   ==  4 )  {
                       
                   
                   
    if (requestobject.status   ==  200  || requestobject.status  == 304 )  {
                                     
                       alert  ("transfer completes") ;
                                             
                                             } else {
                                               
                                                       //error occurred 
                                                     }
                                                     
                                                 }
                                                 
                                           }  
                                           
     var  requestobject   =   new xmlhttprequest();
          
          requestobject.open("get", "http://localhost//login.jsp", true);
                     
          requestobject.onreadystatechange    =  statushandler ;
                       
          requestobject.send();

when the readystate is 4 and status is 200, the response is ready.

note :- onreadystatechange event is triggerd five times (0 to 4),one time for each change in readystate.onreadystatechange event handler a function to be called automatically each time the readystate property changes.


ajax onerror event

the onerror event raised when there is an error that prevents the completion of the cross-domain request.

full description


ajax onload event

the onload event raised when the object has been completely received from the server.

full description


ajax onprogress event

the onprogress event raised when the browser starts receiving data from the server.

full description