chenwq 发表于 2013-1-23 01:35:23

Ajax 异步发送邮件

很多系统中,需要实现,提交表单同时发送邮件通知相关人员的要求.特别在类似OA系统更加常见.
而一般发送邮件都会占用比提交表单+后台对数据处理的时间多很多.
想到两个思路:
1.Ajax异步发送邮件.
2.邮件信息持久化到数据库,数据库定时读取邮件信息,发送邮件

现在使用第一种方式:Ajax异步发送邮件.
<script type="text/javascript">function send_mail(){$.ajax({url: "send_mail_dao.asp",global: false,type: "POST",dataType: "html",async:true,//jQuery API里面所有Demo都使用false,但是这里必须使用Default的true!success: function(){}   })return false;}</script>response.Write "<center><tr><td class='trtif1'><p>此BUG的信息已发送给:"&to_fullnameresponse.Write "<p>BUG已提交成功"response.Write "<p>BUGID="&getidresponse.Write "<p>请记住此Bug的ID号,这会方便你的查询和对此Bug的修复!</td></tr></table>"response.Write "<script type='text/javascript'>"response.Write "send_mail();"response.Write "</script>"// 发送Ajax请求来达到发送邮件之后,页面进行跳转response.Redirect("add_bug_success.asp?toid="&getid)

对async配置项的理解:
Default: trueBy default, all requests are sent asynchronous (i.e. this is set to true by default). If you need synchronous requests, set this option to false. Cross-domain requests and dataType: "jsonp" requests do not support synchronous operation. Note that synchronous requests may temporarily lock the browser, disabling any actions while the request is active.
页: [1]
查看完整版本: Ajax 异步发送邮件