ajax with javascript

26 views

Ajax in javascript contains four parts.
first part makes xml object.
.open(type,url,true or false)
- type denotes method either post or get.
- url denotes file path.
.onreadystatechange
what to do on ajax completion.
- readyState denotes status of ajax request {4 denotes ajax is successfully completed} .

0	The request is not initialized
1	The request has been set up
2	The request has been sent
3	The request is in process
4	The request is complete

send() method sends the request off to the server

  1.  
  2. <script type="text/javascript">
  3. var http_request;
  4. function ajax(url) {
  5.  
  6.   if (window.XMLHttpRequest) { // Mozilla, Safari, IE7…
  7.       http_request = new XMLHttpRequest();
  8.   } else if (window.ActiveXObject) { // IE6 and older
  9.       http_request = new ActiveXObject("Microsoft.XMLHTTP");
  10.   }
  11.  
  12.   http_request.open("POST", url , true);
  13.   http_request.onreadystatechange = alertContents;
  14.  
  15.   http_request.send(null);
  16.  
  17. }
  18.  
  19. function alertContents() {
  20.  
  21.   if (http_request.readyState == 4) {
  22.      
  23.           alert(http_request.responseText);
  24.      
  25.       }
  26.  
  27. }
  28. </script>
  29. <a href="javascript:ajax(’test.xml’)" id="mybutton" name="mybutton">ajax</a>
  30.  



« Customise Your Fading Using fadeTo effect in jquery IE8 creating problem with callback function (jQuery Or Javascript) »
Posted on Monday, April 6th, 2009 at 6:32 pm under Ajax | RSS 2.0 Feed

Post Comment

You must be logged in to post a comment.



ComputerEducationWorld.com All Rights Reserved © RSS | CBSE | Education Boards Of India | What is My IP?