Jump to content

AJAX/XML demo doesn't work on my server


dollhousedoc
 Share

Recommended Posts

I cut and pasted the files for the demo and they don't work on my server. I tried cutting from "view source" as the form-action is a bit different, but it didn't work either (of course I can't "view" the php file).

Can anyone get me headed in the right direction? I have enough PhP to impliment and modify, but not enough to write the code myself. I have done it and re-done the cut-and-pasted files, so I don't believe my cutting and pasting is incomplete.

 

W3 tutorial: http://www.w3schools.com/php/php_ajax_xml.asp

My copy of the listed code in 3 files:

http://calaisvt.info/phpTest/ShowCD.html

Calaisvt.info/phpTest/getcd.php

Calaisvt.info/phpTest/cd_catalog.xml

 

I am trying to make an interractive form that autocompletes from an XML database for the town I live in.

Edited by dollhousedoc
Link to comment
Share on other sites

I have followed this tutorial sequence up to "Show Hint" http://www.w3schools.com/php/php_ajax_php.asp

which runs on my server. But when I uploaded the files for "ShowCD" http://www.w3schools.com/php/php_ajax_xml.asp

it doesn't work.

The html file:

<html><head><script>function showCD(str){if (str=="") { document.getElementById("txtHint").innerHTML=""; return; }if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); }else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } }xmlhttp.open("GET","getcd.php?q="+str,true);xmlhttp.send();}</script></head><body>

<form>Select a CD:<select name="cds" onChange="showCD(this.value)"><option value="">Select a CD:</option><option value="Bob Dylan">Bob Dylan</option><option value="Bonnie Tyler">Bonnie Tyler</option><option value="Dolly Parton">Dolly Parton</option></select></form><div id="txtHint"><b>CD info will be listed here...</b></div>

</body></html>

 

 

Here's the php file:

<?php$q=$_GET["q"];

$xmlDoc = new DOMDocument();$xmlDoc->load("cd_catalog.xml");

$x=$xmlDoc->getElementsByTagName('ARTIST');

for ($i=0; $i<=$x->length-1; $i++){//Process only element nodesif ($x->item($i)->nodeType==1) { if ($x->item($i)->childNodes->item(0)->nodeValue == $q) { $y=($x->item($i)->parentNode); } }}

$cd=($y->childNodes);

for ($i=0;$i<$cd->length;$i++){//Process only element nodesif ($cd->item($i)->nodeType==1) { echo("<b>" . $cd->item($i)->nodeName . ":</b> "); echo($cd->item($i)->childNodes->item(0)->nodeValue); echo("<br>"); }}?>

 

and here's a snip of the xml file:

<?xml version="1.0" encoding="utf-8" ?>- <!-- Edited by XMLSpy -->- <CATALOG>- <CD> <TITLE>Empire Burlesque</TITLE> <ARTIST>Bob Dylan</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Columbia</COMPANY> <PRICE>10.90</PRICE> <YEAR>1985</YEAR> </CD>- <CD> <TITLE>Hide your heart</TITLE> <ARTIST>Bonnie Tyler</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>CBS Records</COMPANY> <PRICE>9.90</PRICE> <YEAR>1988</YEAR> </CD>

</CATALOG>

Edited by dollhousedoc
Link to comment
Share on other sites

I called tech support and they said they support "5.2 and 5.3" (the "server" documentation table has a blank next to "php version"). Things I am running that use php are a plogger photo gallery, a web-to-email script, and I have run wordpress (all of these are several years old).

 

Within the php tutorial, I was able to run the previous php lesson but not this one. Is there something in this code that is version-specific and may not be supported?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...