+ 收藏我們

網(wǎng)站模板

網(wǎng)站模板搜索
404模板 營銷型模板 外貿(mào)網(wǎng)站模板 單頁模板 雙語模板 標(biāo)簽大全

注冊(cè)
網(wǎng)站模板 > cms教程 > pbootcms教程 >

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

AB模板網(wǎng) / 2021-10-11
留言表單

<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>

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ǎng)絡(luò),如有侵權(quán)請(qǐng)聯(lián)系本站,轉(zhuǎn)載請(qǐng)說明出處:http://www.warewashingadvisors.com/pbootcmsjs/9502.html
首頁 pbootcms模板 html模板 會(huì)員中心
 
咨詢
QQ在線咨詢

如無回復(fù)
請(qǐng)加下面的微信

添加微信客

微信客服
wwwadminbuycn