I am trying to intergrate the jquery tokenInput plugin to my form Link I want to simple local data search I want data to be fetched from database and show it in input box with multiple options as in demo However this code works for me it displays the result[i use codeigniter]
//working but want to fetch from database
<script type="text/javascript">
$(document).ready(function() {
$("#demo-input-local").tokenInput([
{id: 7, name: "Ruby"},
{id: 11, name: "Python"},
{id: 13, name: "JavaScript"},
{id: 17, name: "ActionScript"},
{id: 19, name: "Scheme"},
{id: 23, name: "Lisp"},
{id: 29, name: "C#"},
{id: 31, name: "Fortran"},
{id: 37, name: "Visual Basic"},
{id: 41, name: "C"},
{id: 43, name: "C++"},
{id: 47, name: "Java"}
]);
});
</script>
but when I try to fetch data from database it's does not working
here what I have tried in url i have given the url of my controller where my model will be loaded which is responsible for fetching the data.First problem I am facing is how to add HTTP get parameter to my sql and second in getting proper json format which is required to show the result as stated in documentation. Here is code
//My Controller
function get_countries()
{
$this->load->model("register_modal");
$result=$this->register_modal->getCountries();
var_dump($result);
}
//Model for fetching data
function getCountries()
{
$sql = 'SELECT `country_name` FROM nm_country,`$_GET["q"]`';
$query = $this->db->query($sql);
$result = $query->result_array();
return $result;
foreach ($result as $row) {
$json_response = json_encode($row);
}
# Optionally: Wrap the response in a callback function for JSONP cross-domain support
if ($_GET["callback"]) {
$json_response = $_GET["callback"] . "(" . $json_response . ")";
}
echo $json_response;
}
javascript in form
<script type="text/javascript">
$(document).ready(function() {
$("#wish_city").tokenInput('<?php echo base_url('Register/get_countries?queryParam=q')?>',
queryParam: 'q',
tokenLimit: 1,
});
</script>