亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

jQuery下用mockjax提交表單出錯?

jQuery下用mockjax提交表單出錯?

<!DOCTYPE?html> <html?lang="en"> <head> ????<meta?charset="UTF-8"> ????<title>Title</title> ????<link?rel="stylesheet"?href="css/1.css"/> ????<link?rel="stylesheet"?href="css/normalize.css"/> ????<script?src="js/jquery.mockjax.js"></script> ????<script?src="js/jquery-2.2.3.min.js"></script> ????<script?src="js/1.js"></script> </head> <body> name:<input??id="name"?autofocus?placeholder="your?name"?type="text"?> tel:<input?id="tel"?autofocus?placeholder="your?telephone?number"?type="text"> e-mail:<input?id="email"?autofocus?placeholder="your?e-mail"?type="text"> <button?id="btn">submit</button> </body> </html>window.onload?=?function(){ ????$('#btn').click(function?()?{ ????????var?name?=?$('#name').val(); ????????var?tel?=?$('#tel').val(); ????????var?email?=?$('#email').val(); ????????var?data?=?{"name":?name,?"tel":?tel,?"email":email}; ????????console.log(data); ????????$.ajax({ ????????????type:?'POST', ????????????url:?'api/comment/submit', ????????????data:?JSON.stringify(data), ????????????contentType:?"application/json", ????????????dataType:?'json', ????????????success:?function?(data)?{ ????????????????console.log(data); ????????????????if?(data.code?!=?1)?{ ????????????????????//console.log(data.msg); ????????????????????alert(data.msg); ????????????????}?else?{ ????????????????????alert('短信發送成功,我們將盡快聯系您'); ????????????????} ????????????} ????????}); ????????$.mockjax({???????//??固定??必要 ????????????url:?'api/comment/submit',???//?必要?提交到后臺的URL,要與ajax中的url一致 ????????????status:?200,???//響應狀態碼?可選 ????????????responseTime:?1000,???//?響應時間?可選 ????????????responseText:?{????//?固定??必要??{}?花括號內是后臺返回的json數據格式 ????????????????"code":?1, ????????????????"msg":?'success' ????????????} ????????}) ????}) ????};
查看完整描述

1 回答

?
Fiona2017

TA貢獻2條經驗 獲得超0個贊

是不是jq文件要放在mockjax.js文件的前面引用?

查看完整回答
反對 回復 2016-11-15
  • 1 回答
  • 0 關注
  • 1435 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號