ISSUE SOLVED
The issues seemed to be browser related. Tried with a different system and it works fine.
I am coding a live search to show the details of users from database using ajax and php. The input from the form fields are getting passed to the ajax file properly. I checked with console.log() and it is printing properly. After that, the Ajax call takes place without any errors. But when trying to echo the $_POST['search'], it is printing empty space.
searchform.php
<input type="text" placeholder="Search" class="search"/>
<div class="search-result"></div>
search.js
$(function(){
$('.search').keyup(function(){
var search = $(this).val();
//console.log(search);
$.ajax({
url:'search.php',
data:{search:search,},
type:'POST',
success:function(data){
console.log(data);
$('.search-result').html(data);
},
error:function(){
console.log("error");
}
});
});
});
search.php
<?php
include('core/init.php');
echo $_POST['search'];
?>
EDITED
I figured out the issue, but no idea about the cause and no solution found. It is basically that the include('core/init.php');
is not getting included. I tried var_dump(include('core/init.php'));
and it is returning bool(false).The path is correct. Is there something that needs to be done when file with includes
is called using ajax.?