Reputation: 5302
<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 file
<?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;
}
?>
This is the error i'm getting:
This is the code on line 783:
What seemed to be the problem here? I was just following all the instructions in the src folder of tokeninput. I even downloaded their latest version which is in this website: https://github.com/loopj/jquery-tokeninput.
Your help would be greatly appreciated and rewarded!
Thanks!
Upvotes: 0
Views: 1720
Reputation: 781078
Add the following option to the tokenInput call:
propertyToSearch: "Country"
Upvotes: 3