如何从ajax调用php函数 [英] How to call php function from ajax
本文介绍了如何从ajax调用php函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我有一个php函数,我需要从jquery ajax调用它来填充我的数据表。
我尝试过:
我的php文件
Hi
I have a php function and i need to call it from from jquery ajax to populate my datatable.
What I have tried:
my php file
public static function getEmployeesList() {
$list = [];
$dbConn = Connection::getInstance();
$req = $dbConn->query('SELECT firstname,lastname,phone,email FROM employee');
// we create a list of Post objects from the database results
foreach($req->fetchAll() as $post) {
$EmployeesList[] = new Post($post['firstname'], $post['lastname'], $post['phone'],$post['email']);
}
return $EmployeesList;
}
以下jquery
jquery below
tblEmployees = $('#tblEmployees').dataTable({
"oLanguage": { "sEmptyTable": "No data to display" },
"bJQueryUI": false,
"bAutoWidth": false,
"sPaginationType": "full_numbers",
"sAjaxSource": '../EmployeeService.php?method=getEmployeesList()',//problem is here.
推荐答案
list = [];
list = [];
dbConn = Connection :: getInstance();
dbConn = Connection::getInstance();
req =
req =
这篇关于如何从ajax调用php函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文