我对 jquery/ajax 很陌生,在搜索了两天后,我终于寻求帮助。显然有一些我不理解的基本内容。
这是 .ajax 代码:
$.ajax({
url: "../ajax/create_employee.php",
type: 'json',
async: false,
data: $serialFormData,
// callback handler that will be called on success
success: function(response, textStatus, jqXHR){
这是调用的 php 文件 (create_employee.php):
<?php
require ("../models/m_employee.php");
$myemployee = new m_employee();
$response = $myemployee->create_new_employee($_POST);
//echo " php file response = " . $response;
return $response;
?>
这是目标代码:
}
$q = "insert into employee(employee_num,employee_fname,employee_lname,employee_position,employee_start_time,employee_stop_time)";
$q .= "values ('$num','$fname','$lname','$position','$start_time','$stop_time')";
if(!$r = mysqli_query($dbc,$q) ) {
$data['error'] = "true";
$data['message'] = "insert failed";
$data['success'] = "false";
return json_encode($data);
}
返回到调用文件的数据是正确的,但似乎没有进入“成功”函数。返回到 .ajax 调用的数据应该来自我的 create_employee.php 文件还是只是服务器报告该文件已执行?