dollhousedoc Posted March 24, 2014 Share Posted March 24, 2014 (edited) 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 March 24, 2014 by dollhousedoc Link to comment Share on other sites More sharing options...
davej Posted March 24, 2014 Share Posted March 24, 2014 Posting a link to a php file doesn't serve any purpose because no one can read it. I think it might make more sense for you to first test a simpler AJAX example such as... http://www.w3schools.com/ajax/tryit.asp?filename=tryajax_first Link to comment Share on other sites More sharing options...
dollhousedoc Posted March 27, 2014 Author Share Posted March 27, 2014 (edited) 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 March 27, 2014 by dollhousedoc Link to comment Share on other sites More sharing options...
davej Posted March 27, 2014 Share Posted March 27, 2014 So then what version of Php is running on your server? Also what examples have you been able to run successfully? Link to comment Share on other sites More sharing options...
dollhousedoc Posted March 27, 2014 Author Share Posted March 27, 2014 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 More sharing options...
justsomeguy Posted March 27, 2014 Share Posted March 27, 2014 You can use your browser's developer tools to look at the ajax request going out, and check the response from the server. You might see a PHP error message in the response. Link to comment Share on other sites More sharing options...
thescientist Posted March 28, 2014 Share Posted March 28, 2014 What errors are you getting / checking for? What is happening instead? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now