繁体   English   中英

如何使用Ajax调用php类方法

[英]How to call php class method using ajax

我是ajax的新手。 我正在尝试通过表单文本框更改事件中的ajax调用get_mother方法。 我想在数据列表中显示结果。 以下是我使用的代码。

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 
}
}

我的脚本是:

   $(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");
            }
            });

           });
         });

没有警报显示。 请帮我解决问题

我猜没有定义“ dataString”变量。 我认为您应该像这样替换“数据”的值:

data: {mother_name: mother},

还要确保在“ applications / child / child.php”中调用函数get_mother()。

$ChildApplication = new ChildApplication;
$ChildApplication->get_mother();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM