亚洲青青视频一区|8MAV在线观看|天天看AV天天看|中日成人手机在线|欧美激情五区六区|亚洲婷婷天堂级片|亚洲天堂网7777|欧美日韩其他另类|手机在线成人AV|成人性大片一区二区三区四区五区

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

PbootCms 使用Ajax無(wú)刷新提交留言及表單

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

PbootCMS本身對(duì)于使用ajax請(qǐng)求進(jìn)行提交時(shí)會(huì)返回Json數(shù)據(jù),那么我們可以無(wú)需使用API的情況下實(shí)現(xiàn)ajax提交留言,并自定義頁(yè)面提示,提升用戶體驗(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)系銷(xiāo)售
15899750475
在線咨詢
聯(lián)系在線客服,為您解答所有的疑問(wèn)
ARE YOU INTERESTED IN ?
感興趣嗎?

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

15899750475 楊先生