View Single Post
Old 06-19-2016, 09:37 AM  
ludmila20
Registered User
 
ludmila20's Avatar
 
Industry Role:
Join Date: Feb 2016
Posts: 48
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>
__________________
Forbidden Milf Porn Photos
ludmila20 is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook