97超碰在线播放|美女自慰免费观看|亚洲无码三四五区|日韩无码分类大全|日本美女在线99|毛片网女人免费看|亚洲国产香蕉av|久久免费看片视频|超碰在线无码一区|玖玖中文字幕在线

284292114@qq.com 中國站
新聞中心 網(wǎng)絡(luò)推廣 網(wǎng)站建設(shè) 優(yōu)化推廣 首頁>新聞中心>優(yōu)化推廣>建網(wǎng)站

PbootCms 使用Ajax無刷新提交留言及表單

時(shí)間:2019-08-21   訪問量:0

PbootCMS本身對(duì)于使用ajax請(qǐng)求進(jìn)行提交時(shí)會(huì)返回Json數(shù)據(jù),那么我們可以無需使用API的情況下實(shí)現(xiàn)ajax提交留言,并自定義頁面提示,提升用戶體驗(yàn)。


1、留言表單

<form onsubmit="return submsg(this);">
    聯(lián)系人<input type="text" name="contacts" required id="contacts">
    手 機(jī)<input type="text" name="mobile" required id="mobile">
    內(nèi) 容<textarea name="content" id="content"></textarea>
    驗(yàn)證碼<input type="text" name="checkcode" required id="checkcode">
    <img title="點(diǎn)擊刷新" src="{pboot:checkcode}" onclick="this.src='{pboot:checkcode}?'+Math.round(Math.random()*10);" />
    <button type="submit">提交留言</button>
</form>


2、Ajax提交

<script>

//ajax提交留言,由于涉及到提交地址標(biāo)簽的解析,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("謝謝您的反饋,我們會(huì)盡快聯(lián)系您!");
         $(obj)[0].reset(); 
      }else{
         alert(response.data);
      }
    },
    error:function(xhr,status,error){
      alert('返回?cái)?shù)據(jù)異常!');
    }
  });
  return false;
}
</script>


服務(wù)咨詢
1對(duì)1咨詢,專業(yè)客服為您解疑答惑
聯(lián)系銷售
15899750475
在線咨詢
聯(lián)系在線客服,為您解答所有的疑問
ARE YOU INTERESTED IN ?
感興趣嗎?

有關(guān)我們服務(wù)的更多信息,請(qǐng)聯(lián)系項(xiàng)目經(jīng)理

15899750475 楊先生