0

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

3
  • Check stackoverflow.com/questions/17489109/… Commented May 16, 2016 at 13:34
  • Most likely your javascript function is not being called. Before $.ajax({ ... can you check (through console.log()or alert()) that you function is being called? Alternatively, in your browser you can use the network tab in console to check that the AJAX request is being made. Commented May 16, 2016 at 13:46
  • thank u Mr.frederico-falcao Commented May 16, 2016 at 15:13

1 Answer 1

1

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();
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.