我目前使用的是wpIonic (https://github.com/scottopolis/wpIonic),示例使用的是WP-JSON-API V2 (https://wordpress.org/plugins/rest-api/),但我已经为我的需求定制了另一个WP API (https://wordpress.org/plugins/json-api/)。
我遇到的问题是,wpIonic示例使用了JSONP,并且我得到了以下错误
Uncaught SyntaxError: Unexpected token :
http://preview.meeko.me/api/get_posts/?post_type=product&custom_fields=all&_jsonp=JSONP
Object {data: undefined, status: 404, config: Object, statusText: "error"}我目前使用的API不输出JSONP,但是GET请求的DataLoader工厂输出:
.factory('DataLoader', function( $http ) {
return {
get: function(url) {
// Simple index lookup
return $http.jsonp( url );
}
}
})这是在我的控制器中获取post数据的请求:
var postsApi = $rootScope.url + '/api/get_posts/?post_type=product&custom_fields=all&' + $rootScope.callback;
$scope.moreItems = false;
$scope.loadPosts = function() {
// Get all of our posts
DataLoader.get( postsApi ).then(function(response) {
$scope.posts = response.data;
$scope.moreItems = true;
//$log.log(response.data);
}, function(response) {
$log.error(response);
});
}接口和回调
$rootScope.url = 'http://preview.meeko.me';
$rootScope.callback = '_jsonp=JSON_CALLBACK';任何正确方向的指导都将不胜感激。
发布于 2015-11-24 07:58:09
我也有同样的问题,我认为这个问题来自json-rest-api,因为很多其他人使用$http.get(...)、.success()、.error()的V2都有同样的问题;对我来说很好!
https://stackoverflow.com/questions/33277724
复制相似问题