Posted By

SivaramakrishnanM on 09/07/10


Tagged

javascriptajax


Versions (?)

Ajax


 / Published in: JavaScript
 

  1. <html>
  2. <head>
  3. <title>
  4.  
  5. </title>
  6. <script type="text/javascript">
  7.  
  8. //check the code for IE browsers ,and javascript version 5
  9. if(window.ActiveXObject)
  10. {
  11. xmlhttp = new ActiveXObeject("MSxml2.XMLHTTP");
  12. }
  13. // check if the older version of javascript support
  14. else if(window.ActiveXObject)
  15. {
  16. xmlhttp = new ActiveXObeject("Microsoft.XMLHTTP");
  17. }
  18. //this is code for IE7+,Opera,Safari,Chrome,Mozilla
  19. else if(window.XMLHttpRequest)
  20. {
  21. xmlhttp = new XMLHttpRequest();
  22. }
  23.  
  24. function work()
  25. {
  26. var obj =document.getElementById("myDiv");
  27. // u need to create a file of file name ajax_info.php
  28.  
  29. xmlhttp.open("GET","/ajax_info.php",true);
  30. xmlhttp.onreadystatechange=function()
  31. {
  32. if (xmlhttp.readyState==4 ) //where 4 indicates that the request and response have done, similarly there r 0,1,2 and 3
  33. {
  34. obj.innerHTML=xmlhttp.responseText;
  35. }
  36. }
  37.  
  38. xmlhttp.send(null);
  39. }
  40.  
  41. </script>
  42. </head>
  43. <body>
  44. <div id="myDiv"><p>Ajax comes here<p>
  45.  
  46. </div>
  47. <input type="submit" value="Click" name="submit" onclick="work()">
  48.  
  49. </body>
  50. </html>

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: heinz1959 on September 8, 2010

I wonder: isn|'t the query in line 14 exactly the same as in line 9?

Posted By: sivaramakrishnan on September 13, 2010

yeah there r exactly same

You need to login to post a comment.