源码网_提供网站源码、discuz、wordpress主题与插件和站长教程等资源的下载服务

PbootCMS使用Ajax无刷新提交留言及表单

留言表单

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>
8</form>

Ajax提交

01<script>
02//ajax提交留言,由于涉及到提交地址标签的解析,JS需要放在Html文件中
03function submsg(obj){
04var url={pboot:msgaction}; //如果是自定义表单则使用地址{pboot:form fcode=*}
05var contacts=$(obj).find("#contacts").val();
06var mobile=$(obj).find("#mobile").val();
07var content=$(obj).find("#content").val();
08var checkcode=$(obj).find("#checkcode").val();
09
10$.ajax({
11type: POST,
12url: url,
13dataType: json,
14data: {
15contacts: contacts,
16mobile: mobile,
17content: content,
18checkcode: checkcode
19},
20success: function (response, status) {
21if(response.code){
22alert("谢谢您的反馈,我们会尽快联系您!");
23$(obj)[0].reset();
24}else{
25alert(response.data);
26}
27},
28error:function(xhr,status,error){
29alert(返回数据异常!);
30}
31});
32return false;
33}
34</script>

本文链接:https://www.7ov.cn/xinwendongtai/2002.html

版权声明:站内所有文章皆来自网络转载,只供模板演示使用,并无任何其它意义!

联系客服
网站客服 业务合作 在线客服QQ
294169012
微信号
微信号
微信号
返回顶部