Ajax and XML of PHP Novice Ajax and XML
Next we use a case to explain in detail:
Person info will be listed here.
Next we create a php file, the code is as follows:
load("cd_catalog.xml"); $x=$xmlDoc->getElementsByTagName('ARTIST'); for ($i=0; $i<=$x->length-1; $i++) { // 处理元素节点 if ($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++) { // 处理元素节点 if ($cd->item($i)->nodeType==1) { echo("" . $cd->item($i)->nodeName . ": "); echo($cd->item($i)->childNodes->item(0)->nodeValue); echo("
"); } } ?>
When the CD query is sent from JavaScript to the PHP page, it will happen :
1. PHP creates an XML DOM object
2. Finds names in all
3. Outputs the album information and send back the "txtHint" placeholder
Note: This code needs to be copied to local testing, provided that there is the database table we mentioned in the previous section