Home
Technical Training
Ajax Tutorial
This tutorial is part of a Ajax Tutorial tutorial series. Read it from the beginning and learn yourself.
Technical Training
Ajax TutorialAjax, Web Services & XML Part II Page - 2
Page 2 of 2
Author : Exforsys Inc. Published on: 16th Jul 2006
Ajax, Web Services & XML Part II
Ads
Functions Used:
Sample Code
- 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", "<a href="http://www.ignyte.com/whatsshowing/GetTheatersAndMovies" target="_blank" rel="nofollow">http://www.ignyte.com/whatsshowing/GetTheatersAndMovies</a>");
- request.setRequestHeader("User-Agent", "Mindreef SOAPscope 4.1.2000 (<a href="http://www.mindreef.com/" target="_blank" rel="nofollow">http://www.mindreef.com</a>")
- 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="<a href="http://schemas.xmlsoap.org/soap/envelope/" target="_blank" rel="nofollow">http://schemas.xmlsoap.org/soap/envelope/</a>" ';
- xml += 'xmlns:tns="<a href="http://www.ignyte.com/whatsshowing" target="_blank" rel="nofollow">http://www.ignyte.com/whatsshowing</a>" ';
- xml += 'xmlns:xs="<a href="http://www.w3.org/2001/XMLSchema" target="_blank" rel="nofollow">'">http://www.w3.org/2001/XMLSchema" target="_blank" rel="nofollow">'</a>;
- 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;
- }
Copyright exforsys.com
Author: Greg Smith
Read Next: Making Ajax Accessible
Ajax Tutorial
- The Power of Ajax
- Ajax Graphics Enhancement Tools
- How Ajax Can Become as User Friendly as Flash
- How Ajax Can Improve Web Applications
- How Ajax Has Become More Standardized
- Advantages and Disadvantages of Ajax
- The Security Aspects of Ajax
- Ajax Framework
- Ajax Challenges
- Making Ajax Accessible
- Ajax, Web Services & XML Part II
- Ajax, Web Services & XML Part I
- Introduction to Ajax







