如果我从我的controller.js进行这个JSON调用:
$scope.userInvestors = userInvestors.query({UserID:$scope.user.uid},
function(userInvestors) {
console.log("yep yer here");
}
有了这个$resource:
factory('userInvestors', function($resource){
return $resource('http://wherevertheserveris/Rest/userInvestors.php', {}, {
query: {method:'GET', params:{}, isArray:true}
});
})
然后控制台按预期更新为: yep yer here
但是,如果我将请求更改为 JSONP 请求:
$scope.userInvestors = userInvestors.query({UserID:$scope.user.uid,
callback: 'JSON_CALLBACK'}, function(userInvestors) {
console.log("but are you here?");
}
和资源:
factory('userInvestors', function($resource){
return $resource('http://wherevertheserveris/Rest/userInvestors.php', {}, {
query: {method:'JSONP', params:{}, isArray:true}
});
})
即使我知道呼叫已完成并且已检索到数据,控制台也没有打印任何内容?
如何打印 JSONP 日志语句?
ANSWER:
感谢以下两个答案:我需要正确格式化 API 的返回响应。
在 NULL 的情况下,我通过 PHP 返回:print $callback."null";
我需要返回的只是函数包装器内的一个空数组,或者您认为合适的任何其他格式正确的 JSONP 响应。就我而言,是:print $callback."([])";