Jump to content

Ajax Search not working (Help)


Tauheed
 Share

Recommended Posts

Dear Friends, i am trying to make ajax search engine, whenever i will enter text in search field and click on button then search result will not appear. please help me. screen shot and source codes are mentioned below.first page <html><head><link rel="stylesheet" type="text/css" href="style.css" /><title>Ajax Search</title><script type="text/javascript" src="ajax.js"></script><script type="text/javascript"> function getScriptPage(div_id,content_id){subject_id = div_id;content = document.getElementById(content_id).value;http.open("GET", "search.php?content=" + escape(content), true);http.onreadystatechange = handleHttpResponse;http.send(null);} </script><link href="styles.css" rel="stylesheet" type="text/css"></link></head> <body><div class="ajax-div"><div class="input-div">Enter Search Keyword here :<input type="text" id="text_content" size="40"><input type="button" class="button" value="Search" onMouseUp="getScriptPage('output_div','text_content','0')"> </div><div class="output-div-container"><div id="output_div"></div></div></form></div></body></html> 2nd pagesearch.php <?php mysql_connect("localhost", "root", "root") or die("Error connecting to database: ".mysql_error()); mysql_select_db("mysql") or die(mysql_error()); ?> <html><head> <title>Search results</title> </head><body><?php $query = $_GET['content']; // gets value sent over search form $min_length = 1; if(strlen($content) >= $min_length){ // if query length is more or equal minimum length then $query = htmlspecialchars($query); $query = mysql_real_escape_string($query); $raw_results = mysql_query("SELECT * FROM customer_table WHERE `id` = $content") or die(mysql_error()); if(mysql_num_rows($raw_results) > 0){ // if one or more rows are returned do following echo "<table border='1'><tr> <th><h2>Id</h2></th><th><h2>Name</h2></th><th><h2>Regestration No</h2></th><th><h2>Remarks</h2></th></tr>"; while($results = mysql_fetch_array($raw_results)){ echo "<tr>"; echo "<td> " . $results['id'] . "</td>"; echo "<td>" . $results['name'] . "</td>"; echo "<td>" . $results['reg'] . "</td>"; echo "<td>" . $results['remarks'] . "</td>"; echo "</tr>"; }echo "</table>"; } else{ // if there is no matching rows do following echo "No results"; } } else{ // if query length is less than minimum echo "Minimum length is ".$min_length; } ?></body></html>

post-135815-0-79321400-1366097165_thumb.jpg

Link to comment
Share on other sites

You probably shouldn't be returning an entire HTML document from search.php. But I can't tell what the real problem is until I see what the handleHttpResponse() function looks like.

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...