<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;
}
?>
这是我得到的错误:
这是783行上的代码:
这里似乎是什么问题?我只是按照tokeninput的src文件夹中的所有说明进行操作。我什至在以下网站上下载了它们的最新版本:https://github.com/loopj/jquery-tokeninput。
您的帮助将不胜感激和回报!
谢谢!
最佳答案
将以下选项添加到tokenInput调用中:
propertyToSearch: "Country"
关于php - jQuery tokeninput插件上的错误具有“TypeError:术语未定义”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12401507/