难过:无法通过jQuery UI自动完成功能显示结果

问题描述:

我用jquery自动完成功能举了一个简单的示例,但无法使其正常工作.我不知道JSON有什么问题,没有错误,也没有错,但是它不显示结果.

I threw up a simple example with jquery autocomplete and cannot get it to work. I have no idea what's wrong, no errors and nothing's wrong with my JSON, yet it doesn't display results.

这是我的代码

<div class="demo">

<div class="ui-widget">
    <label for="title">Title: </label>
    <input id="test" />
</div>


<script>
$(function() {
        $( "#test" ).autocomplete({
            source: "/searchbackend.php"
        });
});
</script>

JSON:

{"title":["Metroid: Other M"]}

我想您的输出应该像这样["HELLO","HOW","DO","YOU","DO","?"],所以请使用1d数组输出json.

I guess your output should be like this ["HELLO","HOW","DO","YOU","DO","?"] so use 1d array to output json.

$array = array("HELLO", "HOW", "DO", "YOU", "DO", "?");

echo json_encode($array);

男人..这很好用.

$array = array(
                array("label" => "HELLO", "value" => "H"), 
                array("label" => "HOW", "value" => "H"), 
                array("label" => "DO", "value" => "D"),
                array("label" => "YOU", "value" => "Y"),
                array("label" => "DO", "value" => "D"));

echo json_encode($array);

还尝试将source: "/searchbackend.php"更改为source: "searchbackend.php"