<!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('短信發(fā)送成功,我們將盡快聯(lián)系您');
????????????????}
????????????}
????????});
????????$.mockjax({???????//??固定??必要
????????????url:?'api/comment/submit',???//?必要?提交到后臺(tái)的URL,要與ajax中的url一致
????????????status:?200,???//響應(yīng)狀態(tài)碼?可選
????????????responseTime:?1000,???//?響應(yīng)時(shí)間?可選
????????????responseText:?{????//?固定??必要??{}?花括號(hào)內(nèi)是后臺(tái)返回的json數(shù)據(jù)格式
????????????????"code":?1,
????????????????"msg":?'success'
????????????}
????????})
????})
????};
jQuery下用mockjax提交表單出錯(cuò)?
李下之忌心中郁
2016-11-14 10:32:45