×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Text
Posted by: John Lexx
Added: Dec 6, 2016 3:53 PM
Views: 2189
Tags: no tags
  1. var xmlHttp = false;
  2. if(window.XMLHttpRequest){
  3.         xmlHttp = new XMLHttpRequest();
  4. }else if(window.ActiveXObject){
  5.         xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");  
  6. }else if(window.ActiveXObject){
  7.         xmlHttp= new ActiveXObject("Msxml2.XMLHTTP");
  8. }
  9.  
  10. function getAjax()
  11. {      
  12.   var url = "my_xml.xml";      
  13.     if(xmlHttp){                 
  14.         xmlHttp.onreadystatechange = function()
  15.         {
  16.         if(xmlHttp.readyState === 4 && xmlHttp.status === 200){                                
  17.            var data = xmlHttp.responseXML;
  18.                                        
  19.             //var books = data.getElementsByTagName("book");
  20.             // your function;
  21.             // books[i] .getElementsByTagName('author')[0].firstChild.nodeValue
  22.             //books[i] .getElementsByTagName('title')[0].firstChild.nodeValue
  23.            }
  24.          };
  25.                        
  26.         xmlHttp.open("POST", url, true);       
  27.         // xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  28.         xmlHttp.send(null);
  29.      }
  30. }