Friday, March 16, 2012

Web Programming/Scripting: AJAX Examples and Google Maps API

Web Programming/Scripting: AJAX Examples and Google Maps API1 CS 312 Internet Concepts Web Programming/Scripting: AJAX Examples and Google Maps API Dr. Michele Weigle Department of Computer Science Old Dominion University mweigle@cs.odu.edu http://www.cs.odu.edu/~mweigle/CS312-F08/ 2 AJAX and Google Maps !!AJAX Examples »! XML »! Live Search »! RSS Reader »! Poll !!Google Maps API 3 AJAX XML Example !!Components »! HTML form »! XML file »! Javascript »! PHP page "!because we want to use PHP to load XML, we need PHP 5 "!www.cs.odu.edu server has PHP 4 "!webspace.cs.odu.edu

server has PHP 5 "!I wrote a version that only uses Javascript http://www.w3schools.com/php/php_ajax_xml.asp http://webspace.cs.odu.edu/~mweigle/cs312/php5/plants.html http://www.cs.odu.edu/~mweigle/cs312/php/plants.html 4 AJAX XML plants.html
Select a plant:

Plant info will be listed here.

5 AJAX XML selectPlant.js var xmlHttp; function showPlant(str) { xmlHttp=GetXmlHttpObject(); if (xmlHttp==null) { alert ("Browser does not support HTTP Request"); return; } var url="getPlant.php"; url=url+"?q="+str; url=url+"&sid="+Math.random(); xmlHttp.onreadystatechange=stateChanged; xmlHttp.open("GET",url,true); xmlHttp.send(null); } 6 AJAX XML selectPlant.js function stateChanged() { if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { document.getElementById("txtHint").innerHTML=xmlHttp.responseText; } } 7 AJAX XML selectPlant.js function GetXmlHttpObject() { var xmlHttp=null; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; } 8 plant_catalog.xml CATALOG PLANT COMMON BOTANICAL ZONE LIGHT PRICE AVAILABILITY 9 AJAX XML getPlant.php load("../xml/plant_catalog.xml"); $x = $xmlDoc->getElementsByTagName ('COMMON'); for ($i=0; $i<=$x->length-1; $i++) { // Process only element nodes if ($x->item($i)->nodeType == 1) { if ($x->item($i)->childNodes->item(0)->nodeValue == $q) { $y = ($x->item($i)->parentNode); } } } not supported...

Website: www.cs.odu.edu | Filesize: 250kb
No of Page(s): 30
Download Web Programming/Scripting: AJAX Examples and Google Maps API.pdf

No comments:

Post a Comment