drew's autoSuggest plugin help with AJAX results not showing

Posted by s2xi on Stack Overflow See other posts from Stack Overflow or by s2xi
Published on 2011-01-04T08:14:52Z Indexed on 2011/01/04 9:54 UTC
Read the original article Hit count: 392

Filed under:
|
|

hey guys,

i use drew's autoSuggest plugin for some time but up until now I have hard coded my data into my JS, I'm trying to see if I can use AJAX to return the JSON data and query data like that. I seem to have it working but no matter what I try I can't get the results to be shown in the drop down UL it creates via jquery.

The JSON comes back as it should. This is my PHP code:

$input = $_GET["q"];
    $data = array();
    // query your DataBase here looking for a match to $input
    $query = mysql_query("SELECT `state`, `idStates` FROM `states_list` WHERE (`state` LIKE '%{$input}%' OR `abbr` LIKE '%{$input}%')");
    while ($row = mysql_fetch_assoc($query)) {
        $json = array();
        $json['value'] = $row['idStates'];
        $json['name'] = $row['state'];
        $data[] = $json;
    }
    header("Content-type: application/json");
    echo json_encode($data);

and my JS:

$('#state').autoSuggest('resources/ajax/suggest.php', {matchCase: true, minChars: 2, startText: '', emptyText: '', retrieveComplete: function(data){ console.log(data.value) }});

I have been trying to debug so I added the retrieveComplete parameter in there for that.

the PHP returns the AJAX with the JSON content...now just to figure out how to get the JS to pick it up append it to the UL LI

UPDATE:

I appened the data to a test div and its returning

results:[object Object],[object Object],[object Object]

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery