PbootCMS本身對于使用ajax請求進行提交時會返回Json數(shù)據(jù),那么我們可以無需使用API的情況下實現(xiàn)ajax提交留言,并自定義頁面提示,提升用戶體驗。 1、留言表單<form onsubmit="return submsg(this);"> 聯(lián)系人<input type="text" name="contacts" required id="contacts"> 手 機<input type="text" name="mobile" required id="mobile"> 內(nèi) 容<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("謝謝您的反饋,我們會盡快聯(lián)系您!"); $(obj)[0].reset(); }else{ alert(response.data); } }, error:function(xhr,status,error){ alert('返回數(shù)據(jù)異常!'); } }); return false; } </script> |
免責聲明:本站部分文章和圖片均來自用戶投稿和網(wǎng)絡收集,旨在傳播知識,文章和圖片版權歸原作者及原出處所有,僅供學習與參考,請勿用于商業(yè)用途,如果損害了您的權利,請聯(lián)系我們及時修正或刪除。謝謝!
始終以前瞻性的眼光聚焦站長、創(chuàng)業(yè)、互聯(lián)網(wǎng)等領域,為您提供最新最全的互聯(lián)網(wǎng)資訊,幫助站長轉(zhuǎn)型升級,為互聯(lián)網(wǎng)創(chuàng)業(yè)者提供更加優(yōu)質(zhì)的創(chuàng)業(yè)信息和品牌營銷服務,與站長一起進步!讓互聯(lián)網(wǎng)創(chuàng)業(yè)者不再孤獨!
掃一掃,關注站長網(wǎng)微信