当前位置:首页 >> 教程资讯 >> Pboot教程

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

录入编辑:ejjz小编 | 发布时间:2023-01-04
留言表单 查看源码打印代码帮助 1<form onsubmit="return submsg(this);"> 2联系人<input type="text" name="contacts" required id="contacts"> 3手机<input type

留言表单

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>

上一篇:PbootCMS网站提示:“会话目录写入权限不足”的解决办法
下一篇:PbootCMS附件上传失败报错UNKNOW: Code: 8192; Desc: stripos():
热门服务和内容

手机版

  • 官方微信

    扫码进入

  • 客服微信

  • 官方微信

    扫码添加

  • 高端网站设计,顶级互联网服务 Copyright © 2025 www.ejjz.cn All Rights Reserved. 辽ICP备17005629号 XML地图 一键建站
    电话咨询:0411-39550725
    在线客服咨询