請(qǐng)求到數(shù)據(jù),但是沒(méi)在客戶端顯示而且一直彈出200錯(cuò)誤
<script>
$(document).ready(function(){
$("#search").click(function(){
$.ajax({
type:"GET",
url:"getuser.php?username="+$("#keyword").val(),
dataType:"json",
success:function(data){
if(data.success){
$("#searchResult").html(data.msg);
}else{
$("#searchResult").html("出現(xiàn)錯(cuò)誤"+data.msg);
}
},
error:function(jqXHR){
alert("發(fā)生錯(cuò)誤:"+jqXHR.status);
}
});
});
});
</script>
php代碼
function search(){
if(!isset($_GET["username"])||empty($_GET["username"])){
echo "參數(shù)錯(cuò)誤";
return;
}
$da=new user_dal();
$name=$_GET["username"];
$user1=$da->get_a_username($name);
$info=mysql_fetch_array($user1,MYSQL_ASSOC);
? ? $result="用戶名:".$info['username']."密碼:".$info['password'];
? ??
? ? echo $result;
2017-03-17
JS下數(shù)據(jù)是string純文本格式,用的header(“Content-Type”,“text/plain;charset=utf-8”);而jquery下數(shù)據(jù)是json格式,用的應(yīng)該改為header("Content-Type","application/json;charset=utf-8");
希望可以幫到你。
2017-02-04
你要用一個(gè)json來(lái)傳遞,你現(xiàn)在的result是個(gè)純文本,
? ? $result={"success":true,"msg":'"用戶名:".$info['username']."密碼:".$info['password']'};這樣應(yīng)該就可以了
我不知道JSON的格式寫對(duì)了沒(méi)有 你注意一下
2016-11-26
你自己對(duì)比一下源碼