咨询typeahead.js数据库

时间:2014-04-17 19:47:27

标签: javascript php

想使用typeahead.js v.0.10.2查询数据库。 我试过了,但是我失败了,我已经捆绑了这个插件。

JS:

$(document).ready(function() {
            $('input.typeahead').typeahead({
                name: 'user-search',
                remote: 'data.php' // you can change anything but %QUERY
                minLength: 1, // send AJAX request only after user type in at least 3 characters
                limit: 10 // limit to show only 10 results  
 });
});

PHP:

$dato = $_POST['query']; 

 require("connect.inc.php");//database



$query = mysql_query("SELECT artist FROM music WHERE artist REGEXP '^$dato'");

$array = array();


    while($fila = mysql_fetch_array($query)) {
        $array = $fila['artist'];
    }


return json_encode($array);

1 个答案:

答案 0 :(得分:0)

而不是return json_encode($array);使用echo return json_encode($array);