Jquery Ajax json响应在POST方法中未获得成功
在使用jsonp数据类型时,我没有从ajax获得json响应/成功。但我得到的是空白回复。是GAPI的问题,我得到的是这个问题还是其他问题。我发现了类似的问题 这是我的jquery代码Jquery Ajax json响应在POST方法中未获得成功,jquery,jsonp,google-analytics-api,Jquery,Jsonp,Google Analytics Api,在使用jsonp数据类型时,我没有从ajax获得json响应/成功。但我得到的是空白回复。是GAPI的问题,我得到的是这个问题还是其他问题。我发现了类似的问题 这是我的jquery代码 $.ajax({ url: 'includes/gapi.apis.php', data: {action: 'keyword'}, type: 'post', async:false, dataType: "jsonp",
$.ajax({ url: 'includes/gapi.apis.php',
data: {action: 'keyword'},
type: 'post',
async:false,
dataType: "jsonp",
success: function(obj) {
alert(obj);
}
Php代码
$ga->requestReportData(ga_profile_id,array('keyword'),array('visits','pageviews'),array('-visits'),$filter,$startDate, $endDate, $startIndex, $maxResults);
foreach($ga->getResults() as $result)
{
//echo $result->getKeyword()."-------------------".$result->getVisits()."<br>";
$data[$i]['keyword']=$result->getKeyword();
$data[$i]['visits']=$result->getVisits();
$data[$i]['pages_visits']=round(($result->getPageviews())/$result->getVisits(),2);
$i++;
}echo json_encode($data);
$ga->requestReportData(ga_profile_id,数组('keyword'),数组('visions','pageviews'),数组('-visions'),$filter,$startDate,$endDate,$startIndex,$maxResults);
foreach($ga->getResults()作为$result)
{
//echo$result->getKeyword()。“----------------”$result->getvisions()。“
”;
$data[$i]['keyword']=$result->getKeyword();
$data[$i]['visions']=$result->getvisions();
$data[$i]['pages\u visions']=round(($result->getPageviews())/$result->getvisions(),2);
$i++;
}echo json_编码($data);
试试这个
$.ajax({
type: 'POST',
url: "Your url",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType : "json"
success : function (response) {
alert(response.d);
},
error : function (response) {
alert(response.d);
}
})
并且,确保您的代码隐藏函数是WBMETHOD