[英]What is the correct format for a JSON-Array used by angucomplete-alt?
I try to use remote data with angucomplete-alt ( https://github.com/darylrowland/angucomplete ): 我尝试通过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"/>
My PHP-file looks like this: 我的PHP文件如下所示:
$ds = array('title' => 'title', 'description' => 'some text');
$response = array ("results" => $ds);
print_r(json_encode($response));
exit;
So there should always be one single result within searching anything. 因此,在搜索任何内容时始终应该只有一个结果。 But there is just the message 'No results found'. 但是只有消息“未找到结果”。 What am I doing wrong with the JSON-Array? JSON-Array在做什么?
angucomplete-alt needs a top-level array. angucomplete-alt需要一个顶级数组。 So you have to use: 因此,您必须使用:
$response = array ("results" => array($ds));
echo json_encode($response);
Why did you use print_r() ? 为什么使用print_r()?
print_r — Prints human-readable information about a variable print_r —打印有关变量的可读信息
That's probably not what you want. 那可能不是您想要的。
echo json_encode($response);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.