0

I use typeahead.js with Local data source and worked, but when i try to collect data from remote url i have no luck this is my code :

$('#keyword').typeahead({
    minLength: 3,
    remote: 'http://example.com/includes/search.php?g=%QUERY',
    limit: 10
});

and this is my php code :

<? PHP
    $qsrc = mysql_query("SELECT `state_id` AS `all_id`,`name` AS `names`, MATCH(name) AGAINST('".$_REQUEST('g')."') AS `score` FROM `_state` WHERE MATCH(name) AGAINST('".$_REQUEST('g')."' IN BOOLEAN MODE) ORDER BY `score` DESC");
    $arr = array();
    while ($rsrc = mysql_fetch_assoc($qsrc)) {
        $arr[] = array('id' = > $rsrc['all_id'], 'name' = > $rsrc['names']);
    }
    echo json_encode($arr);
?>

did i miss something?

4

1 回答 1

0

这里的答案可能是您正在寻找的。我还强烈建议从 mysql_query 移开并切换到 PDO 语句之类的东西。

正如llundin 指出的那样,您是否确保远程路径在同一个域上?您是否可以在填写了 g 参数的浏览器中打开此 URL 并获得响应?

于 2013-11-25T14:46:15.463 回答