我试图发送电子邮件给多人,一旦电子邮件发送成功,然后我通过ajax响应追加消息。下面的代码工作正常如何在处理时在ajax中添加基于php响应的消息?
腓
if(!empty($sendEmails)){
$sendCount = 0;
foreach($sendEmails as $mail){
$sent = $this->sendEmail('', $mail, $subject, $data);
if($sent != 'Message Sent'){
$response['send_error'][] = 'There is an error with ['.$mail.']';
}else{
$sendCount++;
}
}
}
$response['success'] = 'Email has been sent successfully to '. $sendCount. ' person(s).';
阿贾克斯
$.ajax({
type:'POST',
url:'post.php',
data:formData,
dataType:"json",
success:function(response){
$(".sndMail").remove();
if(response.success){
$(".sendResponse").prepend('<div class="alert alert-success sndMail"> <strong>Alert! </strong> '+response.success+'</div>');
}
if(response.send_error){
for(f=0; f<response.send_error.length; f++) {
//alert(response.fileErr[f]);
$(".sendResponse").prepend('<div class="alert alert-danger sndMail"> <strong>Alert! </strong> '+response.send_error[f]+'</div>');
}
}
if(response.error){
for(f=0; f<response.error.length; f++) {
//alert(response.fileErr[f]);
$(".sendResponse").prepend('<div class="alert alert-danger sndMail"> <strong>Alert! </strong> '+response.error[f]+'</div>');
}
}
}
});
,但我想使用户查看更多良好的通过将每个邮件发送响应。我想在处理过程中附加每条回复消息,如Response: Email is send to [email protected]
,一旦发送完所有电子邮件,我将显示已在使用的成功消息。
那么任何人都可以引导我关于这是可能与ajax或不?如果有人指导我,我想感谢。我搜查了它,但我没有找到解决方案。
我觉得@Mr开发者希望所有的电子邮件被发送之前得到中间结果。 –
@GabrielGlenn完全是 –
在这种情况下,您必须提出多个Ajax请求,这不是一个好主意 –