pbootcms常见问题您现在的位置是:主页 > pbootcms常见问题 >
pbootcms使用Ajax无刷新提交留言及表单
2022-02-13 19:18:08pbootcms常见问题 674人已围观
PbootCMS本身对于使用ajax请求进行提交时会返回Json数据,那么我们可以无需使用API的情况下实现ajax提交留言,并自定义页面提示,提升用户体验。
1、留言表单
<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>2、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>
相关文章
随机图文
TP5框架版本5.0.10安全漏洞修复方案
一、补丁修复1 /thinkphp/library/think/App.php 文件 大概在328行 /** * 执行模块 * @access public * @param array $result 模块/控制器/操作 * @param array $config 配置参数如何解决Chrome 73中bxSlider项目上的click事件的问题?
本文介绍了如何解决Chrome 73中bxSlider项目上的click事件的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 在Chrome更新到版本73之后,不会触发bxSlider的内部项目单击事件,也就是href超链接无效,但是火狐浏览器下正常。 如何为新的Chrome中的元素触发.opbootcms导航菜单{pboot:nav}设置从第几个栏目开始调取
需求说明: 客户的网站菜单比较特别,不适合常规的循环调取显示,现在需要设置下从第三个栏目开始显示。 解决办法: 利用pbootcms的if判断就可以了。 {pboot:nav} {pboot:if('[nav:i]'>'2')} <a href="nav:link">nav:name</a> {/pbootcms定制标签 选择多行文本时 前台调取后 没有换行
加入 decode=1解码数据html字符 如下所示: {label:*** decode=1}