这是我的前端页面,在这里我想显示错误。
<div class="error" style="color:red; text-align:center;"></div>
这是我的后端php验证码:
<?php
$error = array();
$user_id=$_SESSION['email'];
$apply_id=$_SESSION['id'];
$purpose_amount=$_POST['purpose_amount'];
$amount=$_POST['amount'];
$cheque_name=$_POST['cheque_name'];
if(empty($amount)){
$error[] = "Please Enter Expected Amount";
}
elseif(empty($cheque_name)){
$error[] = "Please Enter Issue Cheque in Favour of";
}
if (count($error)) {
echo "<i class='fa fa-exclamation'> ";
echo implode('<br>', $error);
echo "</i>";
}
else{
$result=mysqli_query($conn, "UPDATE education SET amount='$amount', cheque_name='$cheque_name', purpose_amount='$purpose_amount', date='$date' WHERE id='$apply_id'")or die("Could not insert data: " .mysqli_error($conn));
echo $user_id;
}
?>
这是Ajax和Jquery代码:
$('.btn_education_step5').click(function(){
var formdata=new FormData($('#education_step5')[0]);
$.ajax({
url:'includes/backend_education_amount.php',
method: "POST",
async: false,
cache: false,
contentType: false,
processData: false,
data : formdata,
success:function(answer_from_actionpage){
window.location.href = 'education_detail.php?uid='+answer_from_actionpage;
}
error:function(answer_from_actionpage){
$('.error').html(answer_from_actionpage);
}
})
});
当字段为空时,我尝试显示错误。但没有得到回应会发生什么错误。