php - jquery tokeninput 插件错误为 "TypeError: term is undefined"

标签 php javascript jquery

<input type="text" id="demo-input-prevent-duplicates" name="targ_country" />
 <script type="text/javascript">
    $(document).ready(function() {
        var host = window.location.protocol+"//"+window.location.hostname;
        jQuery("#demo-input-prevent-duplicates").tokenInput(host+"/forms/campaign_location.php?action=country", {
        preventDuplicates: true,
        theme: "facebook",
        crossDomain: true
    });
    });
</script>

/forms/campaign_location.php 文件

<?php
if( isset( $_GET['action'] ) && isset( $_GET['q'] ) ) {

    $search = $db->clean( $_GET['q'] );
    $query = sprintf("SELECT CountryId, Country from countries WHERE Country LIKE '%%%s%%' ORDER BY Country DESC LIMIT 10", mysql_real_escape_string($_GET["q"]));
    $result = array();
    $rs = mysql_query($query) or die( mysql_error() );

    while( $row = mysql_fetch_object( $rs ) ) {
        $result[] = $row;
    }

    # JSON-encode the response
    $json_response = json_encode($result);

    if($_GET["callback"]) {
        $json_response = $_GET["callback"] . "(" . $json_response . ")";
    }       
    echo $json_response;
}
?>

这是我收到的错误: enter image description here 这是第 783 行的代码: enter image description here 这里似乎出了什么问题?我只是按照 tokeninput 的 src 文件夹中的所有说明进行操作。我什至在这个网站上下载了他们的最新版本:https://github.com/loopj/jquery-tokeninput .

我们将非常感谢您的帮助并给予奖励!

谢谢!

最佳答案

将以下选项添加到 tokenInput 调用中:

propertyToSearch: "Country"

关于php - jquery tokeninput 插件错误为 "TypeError: term is undefined",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12401507/

相关文章:

javascript - `.then` 和 `.catch` Promise 处理程序是否以某种方式配对并像 `.then(resolutionHandler, rejectionHandler)` 一样对待?

javascript - jQuery UI 可排序取消多个嵌套级别的选项

jquery - 使用附加字段对模型集合进行远程验证

PHP插入查询重新调整成功但没有将数据插入表

php - 在将数据库值传递给 View 之前修改数据库值

javascript - 如何在vuejs中将所有excel数据转换为JSON

javascript - 如何使用 D3.js 限制鼠标事件的函数调用

php - 发送 Excel 文件而不保存在服务器上

php - 需要一些关于使用explode函数从Mysql获取数据的帮助

javascript - Meteor 从另一个方法调用模板方法