【问题标题】:What is the correct format for a JSON-Array used by angucomplete-alt?angucomplete-alt 使用的 JSON 数组的正确格式是什么?
【发布时间】:2023-03-12 17:21:01
【问题描述】:

我尝试通过 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 我做错了什么?

【问题讨论】:

    标签: php json angularjs


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      你为什么使用 print_r() ?

      print_r — 打印关于变量的人类可读信息

      这可能不是你想要的。

      echo json_encode($response);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-11-14
        • 1970-01-01
        • 2015-03-07
        • 2013-08-04
        • 2020-10-22
        • 1970-01-01
        相关资源
        最近更新 更多