老師,為什么請求發(fā)送成功,也有響應(yīng),response也顯示正確,但是無法在前臺顯示?
代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Demo</title>
<style>
body,input,button,select,p,option,h1{font-size:30px;
line-height:1.8;}
</style>
</head>
<h1>員工查詢</h1>
? ? <label>請輸入員工號:</label>
? ? <input type ="text" id = "keywords" /><br />
? ? <button id="search">查詢</button><br />
? ? <p id="researchResult"></p><br />
? ??
? ? <h1>員工新建</h1><br />
? ? <label>請輸入員工姓名:</label>
? ? <input type ="text" id = "staffName" /><br />
? ? <label>請輸入員工號:</label>
? ? <input type ="text" id = "staffNumber" /><br />
? ? <label>請選擇員工性別:</label>
? ? <select id="staffSex">
? ? <option>男</option>
? ? ? ? <option>女</option>
? ? </select><br />
? ? <label>請輸入員工職位:</label>
? ? <input type ="text" id = "staffJob" /><br />
? ? <button id="save">保存</button><br />
? ? <p id="createResult"></p><br />
? ? <script src="http://apps.bdimg.com/libs/jquery/1.11.1/jquery.js"></script>
? ? <script>
$(document).ready(function(){
$("#search").click(function(){
$.ajax({
type:"GET",
url:"service.php?number="+$("#keywords").val(),
dataType:"json",
sunccess:function(data){? //data是成功時(shí)返回的信息,即request.responseText.
if(data.success){
$("#researchResult").html(data.msg);
}else{
$("#researchResult").html("出現(xiàn)錯(cuò)誤"+data.msg);
}
},
error: function(jqXHR){//jqXHR是一個(gè)jquery的XMLHttpRequest對象
alert("發(fā)生錯(cuò)誤:"+jqXHR.status);
}
});
})
$("#save").click(function(){
$.ajax({
type:"POST",
url:"service.php",
dataType:"json",
data:{
name:$("#staffName").val(),
number:$("#staffNumber").val(),
sex:$("#staffSex").val(),
job:$("#staffJob").val()
},
sunccess:function(data){
if(data.success){
$("#createResult").html(data.msg);
}else{
$("#createResult").html("出現(xiàn)錯(cuò)誤"+data.msg);
}
},
error: function(jqXHR){
alert("發(fā)生錯(cuò)誤:"+jqXHR.status);
}
});
})
})
? ? </script>
<body>
</body>
</html>
2018-08-13
php中的json返回值字符串類型需要引號包裹,否則無法解析
2018-03-26
我也是同樣的問題,只不過我是模仿這個(gè)編寫的自己的代碼,但是也是這個(gè)問題,心塞
2017-12-29
還有,你的代碼為什么沒放到body里?
2017-12-29
sunccess:function(data){? //data是成功時(shí)返回的信息,即request.responseText.
sunccess這是什么鬼,這是正確的拼寫嗎?