angucomplete-alt使用的JSON-Array的正确格式是什么?

时间:2015-05-07 03:48:04

标签: php json angularjs

我尝试使用angucomplete-alt(https://github.com/darylrowland/angucomplete)远程数据:

<angucomplete-alt id="searchfield"
      pause="100"
      remote-url="search.php?searchstr="
      remote-url-data-field="results"
      title-field="title"
      description-field="description"
      minlength="1"
      input-class="form-control form-control-small"/>

我的PHP文件如下所示:

$ds = array('title' => 'title', 'description' => 'some text');
$response = array ("results" => $ds);
print_r(json_encode($response));
exit;

因此在搜索任何内容时应始终有一个结果。但是只有消息&#39;没有找到结果&#39;。我对JSON-Array做错了什么?

2 个答案:

答案 0 :(得分:1)

angucomplete-alt需要一个顶级数组。所以你必须使用:

$response = array ("results" => array($ds));
echo json_encode($response);

答案 1 :(得分:0)

为什么使用print_r()?

  

print_r - 打印有关变量的可读信息

这可能不是你想要的。

echo json_encode($response);