对于Anguctey-Alt使用的JSON阵列的正确格式是什么?



我尝试使用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;

因此,在搜索任何内容中总是应该有一个结果。但是只有消息"找不到结果"。我在json-array上做错了什么?

angucomplete-alt需要一个顶级数组。因此,您必须使用:

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

为什么使用print_r()?

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

那可能不是您想要的。

echo json_encode($response);

最新更新