I am trying to implement Typeahead.js to my site.
The typeahead.js will take from a remote page that would return JSON,
something like: http://example.org/search?q=%QUERY
For my site, this is what I've wrote for the PHP:
$q=mysql_real_escape_string($_GET['q']);
$getship= @mysql_query('SELECT * FROM `tbl` WHERE data1 LIKE \'%'.$q.'%\' OR schar LIKE \'%'.$q.'%\';');
while($tbl=mysql_fetch_array($getship)){
$id=$tbl['id'];
$data1=$tbl['data1'];
$fplod=explode(" ",$data1);
$data2=$tbl['data2'];
$splod=explode(" ",$data2);
$data3=$tbl['data3'];
$data4=$tbl['data4'];
echo '{
"value":'.$id.',
"tokens":["'.$fplod[0].'","'.$fplod[1].'","'.$splod[0].'","'.$splod[1].'"],
"data1" :"'.$data1.'",
"data2":"'.$data2.'",
"data3":"'.$data3.'",
"data4":"'.$data4.'"
}';
}
But when ever I ask that typeahead thing to return, it seems to return in text/html and not application/json
.
How can I make this to work?
Thanks in advance