我有一份申请表。这是以前工作但今天它停止正常工作。我提交表单时发生了什么,如果表单有任何错误,它会出现在屏幕上以及网络上。但是当表单提交没有任何错误时,屏幕或网络上不会显示成功消息。也在console.log中尝试过,结果为null。
$bussines_name=$_POST['bussiness_name'];
$email= trim(sanitize_text_field($_POST['emailaddress']));
$url=trim(sanitize_text_field($_POST['websiteaddress']));
$address=trim(sanitize_text_field($_POST['address']));
if(empty($bussines_name) )
{
echo json_encode(array(
'error' => true,
'msg' => 'Please enter your Business Name'
));
exit;
}elseif(empty ($url)){
echo json_encode(array(
'error' => true,
'msg' => 'Please enter your Unique Booking Code'
));
exit;
}elseif (empty ($email)) {
echo json_encode(array(
'error' => true,
'msg' => 'Please enter your email address'
));
exit;
}elseif(empty($address)){
echo json_encode(array(
'error' => true,
'msg' => 'Please enter your address'
));
exit;
} else { echo json_encode(array(
'error' => false,
'msg' => 'Form submit successfully.' // **this msg is showing before but not now.**
));
}
ajax请求网址上的代码
swig
任何帮助都会得到赞赏。
答案 0 :(得分:0)
//you have syntax error which i found I have corrected your code. The error was in line no 4 beform function you was using "(" and at last "}" was missing.
$(document).ready(function (e) {
$("#contactForm1").on('submit',function(e) {
e.preventDefault();
$('p.error').empty();
$('#loader').show();
var siteurl = $(this).attr('action');
$.ajax({
url: siteurl,
type: "POST",
data: new FormData(this),
contentType: false,
cache: false,
processData:false,
dataType:"json",
success: function(data){
if(data.error){
$('#loader').hide();
$( "p.error" ).empty();
$('p.error').css('display','block');
$("p.error").append(data.msg);
}else {
$('#loader').hide();
$( "p.error" ).empty();
$('p.error').css('display','block');
$("p.error").append(data.msg);
window.setTimeout(function(){location.reload()},3000)
}
}
});
});
});