开发者

Doesn't get searchinput via ajax

I have a searchfield which refers to a function to look into my database and get the people I need. That works fine with php, but when I tr开发者_高级运维y to do the same with ajax, it fails.

The searchinput never get posted.

Here's the code. I hope someone has a clue why. Thanks.

Doctor.class.php

public function searchPatients($p_sSearch, $p_iUserid) {
    include("Connection.php"); //open db

    try
    {
        $sql = "SELECT * FROM tblUsers 
                WHERE UserLastname = '".$p_sSearch."'
                and fk_DoctorId = ".$p_iUserid.";";
        $rResult = mysqli_query($link, $sql);
        return $rResult;
    }
    catch(Exception $e)
    {
        // no connection database
        $feedback = $e->getMessage();
    }
    mysqli_close($link);
}

ajax/save.php

include("../classes/Doctor.class.php");

$oDoctor = new Doctor();
    try
    {
    $oDoctor->Search = $_POST['searchinput'];

        $oDoctor->searchPatients($_POST['searchinput'], $_POST['userid']);
    }
    catch (Exception $e)
    {
        $feedback = $e->getMessage();
    }

doctorindex.php

$("#search_overview").hide();
var searchinput = $("#searchinput").val();
$("#searchbutton").live("click", function() {       
    $.post("ajax/save.php", {searchinput: searchinput, 
                            userid: <?php echo $_SESSION['id']; ?>},
            function(data) 
            { 
                $("#patients_overview").hide();
                $("#search_overview").fadeIn();
            });
    return false;
});


It appears that you are getting search input value on page load (when it's empty), not after clicking search button (when you have typed something into it).

You may try:

  • getting search input value directly in .post: {searchinput:$("#searchinput").val()}
  • moving var searchinput into callback function for click event
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜