2

I am trying to use JQuery autocomplete feature using separate php script as source. When I use static table directly in JQuery as source, it works flawlessly:

$(function() {
   $( ".auto" ).autocomplete({
     source: ["Choice1", "Choice2"],
     minLength: 1
   });
});

But when I change the source to the php file (which is located in the same folder), the autocomplete feature doesn't seem to work.

$(function() {
   $( ".auto" ).autocomplete({
     source: 'search.php',
     minLength: 1
   });
});

Here is rest of my code related to autocomplete

Input field:

<tr>
    <div class="ui-widget">
       <td class="tg-031e"><form action="" method="post"><input type="text" class="txtbox auto ui-autocomplete-input" value=""/></form></td>
    </div>
</tr>

Php script:

<?php
    include_once 'php/database_connect.php';
    $searchTerm = $_GET['term'];

    $query = $conn->query("SELECT type FROM material");
    while ($row = $query->fetch_assoc()) {
       $data[] = $row['type'];
    }

    echo json_encode($data);
?>

P.S. Its not up to database connection ($conn), because I use it in other scripts without any problem.

5
  • how is it getting the get variable through that source url? try search.php?term=???? Commented Apr 7, 2016 at 15:14
  • it is not even used now, I pass it just for filtering the results in future. It should list all rows from table Commented Apr 7, 2016 at 15:21
  • don't you use type ahead Commented Apr 7, 2016 at 15:35
  • @RahulSingh I don't get what do you mean, but if I put PHP code inside HTML, with the same SQL query, it returns correct data. Commented Apr 7, 2016 at 16:21
  • did you check out: stackoverflow.com/questions/10371214/… Commented Apr 7, 2016 at 16:52

0

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.