Free Training


C Language  |  CSS  |  MainFrame  |  VBScript  |  PHP  |  XML  |  C++ Tutorials  |  Ajax  |  JavaScript  |  CSS3  |  UML  |  jQuery  |  Microsoft AJAX

Ajax Tutorials

 
Home Tutorials Ajax
 

Ajax, Web Services & XML Part II

 

Ajax, Web Services & XML Part II - Page 2

Page 2 of 2



Functions Used:


function makeCall(url, callback, xml) {
  request = new ActiveXObject("Microsoft.XMLHTTP");
  if (request) {
    var now = new Date();
    request.onreadystatechange = callback;
    request.open("POST", url, true);
    request.setRequestHeader("SOAPAction", "http://www.ignyte.com/whatsshowing/GetTheatersAndMovies");
    request.setRequestHeader("User-Agent", "Mindreef SOAPscope 4.1.2000 (http://www.mindreef.com")
    request.setRequestHeader("Content-Type", "text/xml; charset=UTF-8");
    request.send(xml);
  }
}


function theaters() {
  var zip = document.getElementById("zip").value;
  var radius = document.getElementById("radius").value;
  xml = '<?xml version="1.0" encoding="UTF-8"?>';
  xml += '<soap:Envelope ';
  xml += 'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" ';
  xml += 'xmlns:tns="http://www.ignyte.com/whatsshowing" ';
  xml += 'xmlns:xs="http://www.w3.org/2001/XMLSchema">" target="_blank" rel="nofollow";';
  xml += '   <soap:Body>';
  xml += '      <tns:GetTheatersAndMovies>';
  xml += '         <tns:zipCode>'+zip+'</tns:zipCode>';
  xml += '         <tns:radius>'+radius+'</tns:radius>';
  xml += '      </tns:GetTheatersAndMovies>';
  xml += '   </soap:Body>';
  xml += '</soap:Envelope>';
  document.getElementById("request").value = xml;
  makeCall('http://www.ignyte.com/webservices/ignyte.whatsshowing.webservice/moviefunctions.asmx" target="_blank" rel="nofollow"', updateMe, xml);
}


function updateMe() {
  if (request.readyState != 4) return;
  if (request.status != 200) return;
  html = "";
  var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
  xmlDoc.loadXML(request.responseText);
  dfs(xmlDoc);
  document.getElementById("request").value = request.responseText;
  document.getElementById("result").innerHTML = html;
  request.abort();
  request = null;
}


function dfs(node) {
  var stuff = "";
  for(var i=0; i<node.childNodes.length; i++) {
    var thisNode = node.childNodes(i);
    if (thisNode.nodeName == "Theater") {
      html += theater(thisNode) + "\n";
    } else {
      dfs(thisNode);
    }
  }
  return stuff;
}


function theater(node) {
  var stuff = "";
  for(var i=0; i<node.childNodes.length; i++) {
    var thisNode = node.childNodes(i);
    if (thisNode.nodeName == "Name") {
      stuff += "<h1>"+thisNode.childNodes(0).nodeValue+"</h1>\n";
    } else if (thisNode.nodeName == "Address") {
      stuff += "<h2>"+thisNode.childNodes(0).nodeValue+"</h2>\n";
    } else if (thisNode.nodeName == "Movies") {
      stuff += movies(thisNode);
    }
  }
  return stuff;
}


function movies(node) {
  var stuff = "<table border=1>";
  for(var i=0; i<node.childNodes.length; i++) {
    var thisNode = node.childNodes(i);
    if (thisNode.nodeName == "Movie") {
      stuff += "<tr>"+movie(thisNode)+"</tr>";
    }
  }
  return stuff+"</table>";
}


function movie(node) {
  var stuff = "";
  for(var i=0; i<node.childNodes.length; i++) {
    var thisNode = node.childNodes(i);
    if (thisNode.nodeName == "Rating") {
      stuff += "<td>"+thisNode.childNodes(0).nodeValue+"</td>";
    } else if (thisNode.nodeName == "Name") {
      stuff += "<td>"+thisNode.childNodes(0).nodeValue+"</td>";
    } else if (thisNode.nodeName == "RunningTime") {
      stuff += "<td>"+thisNode.childNodes(0).nodeValue+"</td>";
    } else if (thisNode.nodeName == "ShowTimes") {
      stuff += "<td>"+thisNode.childNodes(0).nodeValue+"</td>";
    }
  }
  return stuff;
}


Download Sample Code


Author: Greg Smith




First Page: Ajax, Web Services & XML Part II


Read Next: Making Ajax Accessible



 

 

Comments



Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Weekly Offers

Sponsored Links