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

分  类: pbootcms教程

统  计:221 次获取

创建时间: 2024-03-21 14:25:32

  • 详情介绍
13+年专注全栈开发,承接小程序开发,分销系统定制,网站建设、搬家、搭建,二次开发等一站服务,欢迎咨询
留言表单

<form onsubmit="return submsg(this);"> 联系人<input type="text" name="contacts" required id="contacts"> 手 机<input type="text" name="mobile" required id="mobile"> 内 容<textarea name="content" id="content"></textarea> 验证码<input type="text" name="checkcode" required id="checkcode"> <img title="点击刷新" src="{pboot:checkcode}" onclick="this.src='{pboot:checkcode}?'+Math.round(Math.random()*10);" /> <button type="submit">提交留言</button></form>

Ajax提交

<script>//ajax提交留言,由于涉及到提交地址标签的解析,JS需要放在html文件中function submsg(obj){ var url='{pboot:msgaction}'; //如果是自定义表单则使用地址{pboot:form fcode=*} var contacts=$(obj).find("#contacts").val(); var mobile=$(obj).find("#mobile").val(); var content=$(obj).find("#content").val(); var checkcode=$(obj).find("#checkcode").val(); $.ajax({ type: 'POST', url: url, dataType: 'json', data: { contacts: contacts, mobile: mobile, content: content, checkcode: checkcode }, success: function (response, status) { if(response.code){ alert("谢谢您的反馈,我们会尽快联系您!"); $(obj)[0].reset(); }else{ alert(response.data); } }, error:function(xhr,status,error){ alert('返回数据异常!'); } }); return false;}</script>

PbootCMS使用Ajax无刷新提交留言及表单_pbootcms教程 栏目文章由:源码庄整理发布,转载请注明来源。
来源地址:https://www.codenet.cc/article/details/13.html
本站资源未标注正版授权软件均为会员提供或网上搜集,版权归原作者所有,如需商业用途或转载请与原作者联系;
发布的文章及附件仅限用于学习和研究目的,请勿用于商业或违法用途!如有侵权,请及时联系我们!
《更多用户服务协议声明》
  • 波浪
  • 波浪
  • 波浪
  • 波浪