如何从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 =