By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,515 Members | 1,178 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,515 IT Pros & Developers. It's quick & easy.

ajax display status problem

100+
P: 108
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 ?

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3.     <script type="text/javascript">    
  4.         function tr(){
  5.             if (window.XMLHttpRequest)     // Object of the current windows
  6.                 { 
  7.                         xhr = new XMLHttpRequest();   alert("firefox");  // Firefox, Safari, ...
  8.                 } 
  9.             else 
  10.                  if (window.ActiveXObject)   // ActiveX version
  11.                      {
  12.                             xhr = new ActiveXObject("Microsoft.XMLHTTP");alert("IE");  // Internet Explorer 
  13.                      } alert(xhr.readyState);
  14.  
  15.                       xhr.onreadystatechange =function chk(){
  16.                             if (xhr.readyState == 4)
  17.                                 {
  18.                                       alert("I am ready");
  19.                                 } else 
  20.                                     {
  21.                                          alert("I am not ready");
  22.                                     }
  23.                     }
  24.             }
  25.  
  26. </script>
  27. </head>
  28. <body>
  29. <button onclick="tr()">tryme</button>
  30.  
  31.  
  32. </body>
  33. </html>
  34.  

Thanks in adv
Feb 22 '10 #1
Share this Question
Share on Google+
1 Reply


RamananKalirajan
100+
P: 607
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
Feb 22 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.