Reputation: 21
I'm new to ajax. I'm trying to call get_mother method through ajax in my form textbox change event. I want to show results in datalist. below is the code i have used.
class ChildApplication extends Application{
function __construct(){
$this->login_required();
}
function get_mother(){
$mother = $_POST['mother_name'];
$mother = '%'.$mother.'%';
$db=$this->get_dbo();
$sql = "SELECT * FROM tbl_mother WHERE `mother_fname` LIKE ? ";
$results = $db->load_result($sql,array($mother));
return $results;
}
function get_child($mother){
//statements
}
}
My script is:
$(document).ready(function(){
$("#mother_name").keyup(function(event){
event.preventDefault();
var mother = $("#mother_name").val();
$.ajax({
type: 'POST',
url: 'applications/child/child.php',
data: dataString,
dataType: 'json',
success: function(){
alert("pass");
},
error: function(){
alert("error");
}
});
});
});
none of alerts are displayed. please help me to solve the problem
Upvotes: 0
Views: 1600
Reputation: 1795
I guess that "dataString" variable is not defined. I think that you should replace the value of "data" like this:
data: {mother_name: mother},
Also make sure that the function get_mother() is called in "applications/child/child.php"
$ChildApplication = new ChildApplication;
$ChildApplication->get_mother();
Upvotes: 1