2013-05-13 30 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。