I have written some script to auto fill the search input (search data from database), Along with query I am sending some dynamic variable in remote url for advanced search .
But I am not receiving any data in destination file , if sent only query in 'remote' its working fine but along with dynamic variable in remote url its not working ! please check my code and guide me where I am wrong
<script src="typeahead.min.js"></script>
<script>
$(document).ready(function(){
$('input.typeahead').typeahead({
name: 'typeahead',
//remote:'subtasksearch.php?key=%QUERY',
//remote:'subtasksearch.php?key=%QUERY&&mani=123',
remote: {
url: 'subtasksearch.php?key=%QUERY&&mani=',
replace: function () {
var q = 'subtasksearch.php?key=%QUERY&&mani=';
if ($('#country').val()) {
q += encodeURIComponent($('#country').val());
}
return q;
}
},
limit : 10
});
});
</script>
And my subtasksearch.php is
<?php
$key=$_GET['key'];
$mani=$_GET['mani'];
$array = array();
$con=mysqli_connect("localhost","","","");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$query=mysqli_query($con, "select * from sub_task where name LIKE '%{$key}%'");
while($row=mysqli_fetch_assoc($query))
{
$array[] = $row['name'];
//$array[] = $mani;
}
echo json_encode($array);
And my search input is
<input type="text" name="typeahead" class="typeahead tt-query" autocomplete="off" spellcheck="false" placeholder="Type your Task" required="">
If you use simple remote to send query its working fine
remote:'subtasksearch.php?key=%QUERY',
//or
remote:'subtasksearch.php?key=%QUERY&&mani=123',
With dynamic variable in remote url is not working , I have observed few things in console the data is passing in URL and returning empty array I guess please check the bellow image
Please guide Me where I am wrong! Is I am sending values in wrong way ?