angularjs $http.jsonp goes to .error instead of .success even when 200 is received

angularjs

Solution

You must return a valid JSON response on the server side. The 200 OK is just the GET request that is injected into the DOM. I bet you are not returning a valid JSON response from the server with right response code.

Here is an example on how to construct the response on the server side (PHP): Simple jQuery, PHP and JSONP example?

Problem

I'm building an AngularJS app which calls a NodeJS server that gets data from a DB. The NodeJS returns a JSON.stringify(someArrayWithData). Here is the AngularJS code: ``` $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; }); }; ``` $scope.MainGroups is going to the .error instead to the success even when I can see in the chrome debugger that the result came back (200 ok). What am I missing?

Original source

Related problems