jquery tokeninput插件上的错误为";TypeError:术语未定义; $(文档).ready(函数(){ var host=window.location.protocol+“/”+window.location.hostname; jQuery(“#演示输入防止重复”).tokenInput(主机+”/forms/campaign_location.php?action=country“{ 重复:正确, 主题:“facebook”, 跨域:对 }); });

jquery tokeninput插件上的错误为";TypeError:术语未定义; $(文档).ready(函数(){ var host=window.location.protocol+“/”+window.location.hostname; jQuery(“#演示输入防止重复”).tokenInput(主机+”/forms/campaign_location.php?action=country“{ 重复:正确, 主题:“facebook”, 跨域:对 }); });,php,javascript,jquery,Php,Javascript,Jquery,/forms/campaign_location.php文件 <input type="text" id="demo-input-prevent-duplicates" name="targ_country" /> <script type="text/javascript"> $(document).ready(function() { var host = window.location.protocol+"//"+window.locati

/forms/campaign_location.php文件

<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>

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

<?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;
}
?>

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

<?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;
}
?>


$json_response
的输出是什么?样本输出:jquery1710856799442267607_1347521889033([{“CountryId”:“268”,“Country”:“西萨摩亚”},{“CountryId”:“267”,“Country”:“西撒哈拉”},{“CountryId”:“255”,“Country”:“美国小离岛”},{“CountryId”:“254”,“Country”:“美国”},{“CountryId”:“253”,“Country”:“联合王国”},{“CountryId”:“252”,“国家”:“阿拉伯联合酋长国”},{“CountryId”:“216”,“国家”:“塞尔维亚和黑山”},{“CountryId”:“275”,“国家”:“巴勒斯坦领土,被占领”},{“CountryId”:“166”,“国家”:“黑山”},{“CountryId”:“160”,“国家”:“密克罗尼西亚联邦”})根据插件中的文档,格式应该是
{“id”:“253”,“name”:“United Kingdom”},
你试过了吗?是的,我试过了,但仍然不起作用。之所以采用这种格式,是因为我添加了一个跨域:True,
$json_response
的输出是什么?示例输出:jQuery71085667994422676071347521889033([{“CountryId:“268”,“Country:“Western Samoa”},{“CountryId:“267”,“Country:”西撒哈拉{“CountryId”:“255”、“国家”:“美国小离岛”}、{“CountryId”:“254”、“国家”:“美国”}、{“CountryId”:“253”、“国家”:“联合王国”}、{“CountryId”:“252”、“国家”:“阿拉伯联合酋长国”}、{“CountryId”:“216”、“国家”:“塞尔维亚和黑山”}、{“CountryId”:“275”、“国家”:“巴勒斯坦领土,被占领”},{“CountryId:“166”,“Country:“Montegon”},{“CountryId:“160”,“Country:“密克罗尼西亚联邦”}])根据插件中的文档,格式应为
{“id:“253”,“name:“United Kingdom”},
你试过了吗?是的,我试过了,但仍然不起作用。之所以采用这种格式,是因为我添加了一个跨域:trueWow!它很有魅力!谢谢你的这个!我还没有在文档中读到它。:)我还有一个问题,插件认为我搜索的国家是一个重复的国家。这是视频我很难在这里解释它。你看了视频了吗?如果是的,那么你会从那里得到它。链接在我们的注释上方。重复检查使用
id
属性,但你不会在JSON中返回它。将SQL更改为
选择CountryID作为id,
。哇!因此这个插件识别了两个属性,我d和名称属性。谢谢你的帮助!:)哇!这就像一个符咒!谢谢这一个!我没有在文档中读到它。:)我有另一个问题,插件认为我搜索的国家是一个重复的国家。这是我很难解释的视频。你看了视频了吗?如果是,那么你会得到它从那里开始。链接在我们的注释上方。重复检查使用
id
属性,但您不会在JSON中返回它。将SQL更改为
选择CountryID作为id,
。哇!因此此插件识别了两个属性,id和name属性。感谢您的帮助!:)