PbootCMS使用Ajax無(wú)刷新提交留言及表單
留言表單
1<form onsubmit="return submsg(this);">
2聯(lián)系人<input type="text" name="contacts" required id="contacts">
3手 機(jī)<input type="text" name="mobile" required id="mobile">
4內(nèi) 容<textarea name="content" id="content"></textarea>
5驗(yàn)證碼<input type="text" name="checkcode" required id="checkcode">
6<img title="點(diǎn)擊刷新" 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提交留言,由于涉及到提交地址標(biāo)簽的解析,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("謝謝您的反饋,我們會(huì)盡快聯(lián)系您!");
23$(obj)[0].reset();
24}else{
25alert(response.data);
26}
27},
28error:function(xhr,status,error){
29alert(返回?cái)?shù)據(jù)異常!);
30}
31});
32return false;
33}
34</script>
本文鏈接:http://m.www9463.cn/xinwendongtai/2002.html
版權(quán)聲明:站內(nèi)所有文章皆來(lái)自網(wǎng)絡(luò)轉(zhuǎn)載,只供模板演示使用,并無(wú)任何其它意義!