jqueryajax等待php响应过程
我正在使用ajax函数发送数据。在php过程中,我运行phpmailer使用smtp gmail发送电子邮件。一切都进行得很顺利,但在某些情况下,我希望将信息发送给用户,以等待正在进行的过程。我的代码:jqueryajax等待php响应过程,php,jquery,phpmailer,Php,Jquery,Phpmailer,我正在使用ajax函数发送数据。在php过程中,我运行phpmailer使用smtp gmail发送电子邮件。一切都进行得很顺利,但在某些情况下,我希望将信息发送给用户,以等待正在进行的过程。我的代码: LoadingProccess(); var FormData = $('#subscribe').serialize(); $.ajax({ type: "POST", url: "proses_corporate.php", data: FormData,
LoadingProccess();
var FormData = $('#subscribe').serialize();
$.ajax({
type: "POST",
url: "proses_corporate.php",
data: FormData,
cache: false,
dataType: "json",
success: function(data){
var cek = data.result;
$.unblockUI();
if(cek=='Success'){
$('#subscribe')[0].reset();
$.blockUI({
message: '<h4>'+data.status+'</h4>',
timeout: 8000 ,
css: {
top: ($(window).height() - 100) /2 + 'px',
left: ($(window).width() - 650) /2 + 'px',
width: '650px'
});
setTimeout(function() {
window.location.href = 'http://www.domain.com/';
}, 8000);
}
setTimeout(function() {
window.location.href = 'http://www.domain.com/';
}, 8000);
}
},
error: function() {
alert('Error');
}
});
使用
smtpmailer('bertho_joris@yahoo.co.id','berthojoris@gmail.com','GMAIL','Testing Form GMail','Test...Test...Test...Test...');
echo json_encode(array('status' => 'Data has been sent.', 'result' => 'Success'));
与上面的代码一样,表单将在成功处理后路由到特定页面。在我的例子中,jQuery如何在翻页之前等待动态php的结果
您是否必须在jQuery上使用超时:10000?它似乎不是动态的,因为时钟是手动设置的。还有其他方法吗?您可以在页面上放置一个掩码,使其在功能上可见并消失或重定向页面您可以使用beforeSend功能添加掩码。
完成功能后,取下遮罩 等待响应时,会延长ajax请求超时时间。e、 g
$.ajax({
type: "POST",
url: "proses_corporate.php",
data: FormData,
cache: false,
timeout: 30000, // 3 second
dataType: "json",
success: function(res){ },
failed: function(err){ }
}
如果出现任何错误,是否要重定向到另一个成功页面并显示一些错误消息?是的……但是在php进程之后,您可以为“if(cek=='Success')”语句添加一个else块,并在php进程未返回“Success”时显示错误/重定向到另一个页面。如果进程失败,我会生成一个else块。我的问题是指成功的过程,但我仍然没有理解你的问题
$.ajax({
type: "POST",
url: "proses_corporate.php",
data: FormData,
cache: false,
timeout: 30000, // 3 second
dataType: "json",
success: function(res){ },
failed: function(err){ }
}