angularjs $ http.jsonp即使收到200也会转到.error而不是.success

Alo*_*lon 3 angularjs

我正在构建一个AngularJS应用程序,它调用从数据库获取数据的NodeJS服务器.NodeJS返回JSON.stringify(someArrayWithData).

这是AngularJS代码:

$scope.getMainGroups = function(){
    $http.jsonp("http://127.0.0.1:3000/get/MainGroups?callback=JSON_CALLBACK").success(function(data, status, headers, config) {
            $scope.MainGroups = data;
        }).error(function(data, status, headers, config) {
            $scope.MainGroups = status;
        });
};
Run Code Online (Sandbox Code Playgroud)

即使我在chrome调试器中看到结果返回(200 ok),$ scope.MainGroups也会转到.error而不是成功.

我错过了什么?

Uku*_*kit 6

您必须在服务器端返回有效的JSON响应.200 OK只是注入DOM的GET请求.我敢打赌你没有从服务器返回有效的JSON响应和正确的响应代码.

下面是一个如何在服务器端构建响应的示例(PHP): 简单的jQuery,PHP和JSONP示例?