PbootCMS本身对于使用ajax请求进行提交时会返回Json数据,那么我们可以无需使用API的情况下实现ajax提交留言,并自定义页面提示,提升用户体验。
1、留言表单
1 | <form onsubmit= "return submsg(this);" > |
2 | 联系人<input type = "text" name= "contacts" required id = "contacts" > |
3 | 手 机<input type = "text" name= "mobile" required id = "mobile" > |
4 | 内 容<textarea name= "content" id = "content" ></textarea> |
5 | 验证码<input type = "text" name= "checkcode" required id = "checkcode" > |
6 | <img title= "点击刷新" src= "{pboot:checkcode}" onclick= "this.src='{pboot:checkcode}?'+Math.round(Math.random()*10);" /> |
7 | <button type = "submit" >提交留言</button> |
|
2、Ajax提交
03 | //ajax提交留言,由于涉及到提交地址标签的解析,JS需要放在html文件中 |
05 | var url= '{pboot:msgaction}' ; //如果是自定义表单则使用地址{pboot:form fcode=*} |
06 | var contacts=$(obj). find ( "#contacts" ).val(); |
07 | var mobile=$(obj). find ( "#mobile" ).val(); |
08 | var content=$(obj). find ( "#content" ).val(); |
09 | var checkcode=$(obj). find ( "#checkcode" ).val(); |
21 | success: function (response, status) { |
23 | alert( "谢谢您的反馈,我们会尽快联系您!" ); |
29 | error: function (xhr,status,error){ |
|
发表评论
评论列表(0条)