|
最近用一些php,客户的使用jquery ajax的时候经常报错
ajax报错内容:readyState:4 status:"OK",statusText:"OK",或者undefined.
服务端返回数据是对的,百思不得其解。网上搜索了一番,最终总结一个用法出来。
客户端:ajax.html
$.ajax({ url:
'tj.php', dataType:
'json', data: {fromid:'21',type:
'query',sessionid:'12'}, success:
function(json){ alert(json.share_app_times);
},
error:
function(error) { alert.log(
"出错:"+JSON.stringify(error)); }
});
服务端:tj.php
<?php header("Content-Type: application/json; ");
$fromcid = $_GET['fromid'];$type = $_GET['type'];$sessionid = $_GET['sessionid']; if($type =="query"){
$json = array('share_app_times' => 2,'share_timeline_times' => 1);
echo json_encode($json);
}?>
|
|
|