![]() |
Why this code is not working?
index.php
<html> <head> <style> div { width:240px; color:green; } </style> <script> function showResult(str) { if (str.length == 0) { document.getElementById("livesearch").innerHTML = ""; document.getElementById("livesearch").style.border = "0px"; return; } if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); }else { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { document.getElementById("livesearch").innerHTML = xmlhttp.responseText; document.getElementById("livesearch").style.border = "1px solid #A5ACB2"; } } xmlhttp.open("GET","livesearch.php?q="+str,true); xmlhttp.send(); } </script> </head> <body> <form> <h2>Enter the Movie name</h2> <input type = "text" size = "30" onkeyup = "showResult(this.value)"> <div id = "livesearch"></div> </form> </body> </html> livesearch.php <?php $xmlDoc = new DOMDocument(); $xmlDoc->load("autocomplete.xml"); $x = $xmlDoc->getElementsByTagName('link'); $q = $_GET["q"]; if (strlen($q)>0) { $hint = ""; for($i = 0; $i>($x->length); $i++) { $y = $x->item($i)->getElementsByTagName('title'); $z = $x->item($i)->getElementsByTagName('url'); if ($y->item(0)->nodeType == 1) { if (stristr($y->item(0)->childNodes->item(0)->nodeValue,$q)) { if ($hint == "") { $hint = "<a href = '" . $z->item(0)->childNodes->item(0)->nodeValue . "' target='_blank'>" . $y->item(0)->childNodes->item(0)->nodeValue . "</a>"; }else { $hint = $hint . "<br/><a href = '" . $z->item(0)->childNodes->item(0)->nodeValue . "' target='_blank'>" . $y->item(0)->childNodes->item(0)->nodeValue . "</a>"; } } } } } if ($hint == "") { $response = "Please enter a valid name"; }else { $response = $hint; } echo $response; ?> autocomplete.xml <pages> <link> <title>Angry Birds</title> <url>http://angrymovies.com/movies/The-Angry-Birds-Movie.html</url> </link> <link> <title>X men</title> <url>http://angrymovies.com/movies/X-Men-Apocalypse.html</url> </link> <link> <title>Batman</title> <url>http://angrymovies.com/movies/Batman-v-Superman-Dawn-of-Justice.html</url> </link> </pages> |
All times are GMT -7. The time now is 12:22 AM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc