ajax display status problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • phpuser123
    New Member
    • Dec 2009
    • 108

    ajax display status problem

    Hi,
    I have recently been going through ajax tutorials and i came up with the following codes..I am getting my readystate to be 0 which means it is nt initialised.Why don't I get a code of 4 and what doesn the code 0 really mean? How can I solve this problem ?

    Code:
    <html>
    <head>
    	<script type="text/javascript">	
    		function tr(){
    			if (window.XMLHttpRequest)     // Object of the current windows
    				{ 
       					 xhr = new XMLHttpRequest();   alert("firefox");  // Firefox, Safari, ...
    				} 
    			else 
    				 if (window.ActiveXObject)   // ActiveX version
    					 {
      						  xhr = new ActiveXObject("Microsoft.XMLHTTP");alert("IE");  // Internet Explorer 
     					} alert(xhr.readyState);
    					
    					  xhr.onreadystatechange =function chk(){
    							if (xhr.readyState == 4)
    								{
      									alert("I am ready");
    								} else 
    									{
     										alert("I am not ready");
    									}
    					}
    			}
    			
    </script>
    </head>
    <body>
    <button onclick="tr()">tryme</button>
    
    
    </body>
    </html>

    Thanks in adv
  • RamananKalirajan
    Contributor
    • Mar 2008
    • 608

    #2
    The code what you have posted here is not completed one. For an Ajax statement a submission should be done. What you have did so far is creation of XMLHttpRequest object only. Using that object only you can make an Ajax call. Regarding the readstate code, following are the codes and its status

    0 = uninitialized
    1 = loading
    2 = loaded
    3 = interactive
    4 = complete

    Thanks and Regards
    Ramanan Kalirajan

    Comment

    Working...