0

I am working with jQuery autocomplete plugin and this is my index:

<script> 
  $(document).ready(function(){
    $("#tag").autocomplete({source: "./search.php?q="+ $("#tag").val()});
   });
</script>

<form action="search.php" method="post" class="form-inline search">
  <input type="text" id="tag" name="tag">
  <input type="submit" class="btn" value="Search" />
</form>

in search.php which is in the same folder as index.php is following:

 include 'config.php';
 $q=$_GET['q'];
 $my_data=mysql_real_escape_string($q);

 $sql="SELECT * FROM tags WHERE tag LIKE '%$my_data%'";
 $result = mysql_query($sql) or die(mysql_error());

 if($result)
 {
  while($row=mysql_fetch_array($result))
  {
   echo $row['tag']."\n";
  }
 }

When I start typing, autocomplete doesn't offer me any suggestions. Also no errors in JS console. In the code is just displayed No search results.. The paths are set up correctly, the database connection as well.

Thus, where could be a problem?

Thank you

2
  • do you see any results when you access search.php?q=something directly? Commented Jan 5, 2013 at 1:24
  • Yes, I see the results there, on the blank page. Commented Jan 5, 2013 at 1:27

2 Answers 2

1

You don't need to use a query string on the src url of autocomplete. Just write your src file without query string:

$("#tag").autocomplete({source: "./search.php"});

And in your php file you have to capture the term parameter:

$q = $_GET['term'];
Sign up to request clarification or add additional context in comments.

Comments

0

Solved this way - in PHP file must be data returned in JSON:

while($row=mysql_fetch_array($data))
{
    $result[] = $row['tag'];
}
echo json_encode($result);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.