2013-05-13 31 views
2

我在使用jsonp數據類型時沒有從ajax獲取json響應/成功。但我正在逐漸空白response.Is是GAPI的我得到這個問題或任何other.I發現類似的問題 Not able to get the json responseAjax json在POST方法中未成功響應

,這是我的jQuery代碼

$.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); 

回答

0

試試這個。

$.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。