最近用一些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; charset=utf-8");
$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); }?>