Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angularJS $http not stripping off prefix

Tags:

angularjs

As per this documentation, AngularJS will strip off the prefix )]}',\n in the JSON responses. I am sending my JSON responses with the prefix in my JSON responses but AngularJS is not stripping off the prefix and interpreting the results. Any idea? Thanks.

I sent the responses back from Spring as described here. And it's sending JSON response with the prefix )]}',\n. In AngularJS, I need to retrieve the values:

var Retrieve = $resource('app/', {..});

and in the success call back function:

var successQuestions = function (q) {
    $rootScope.q1 = q.question1;
};

I am expecting q JSON to be properly interpreted by AngularJS as a JSON but it is not.

like image 533
user203617 Avatar asked May 18 '26 00:05

user203617


1 Answers

I had the same problem, and noticed that the xhr object thought the response was null. The problem for me was that I had responseType: 'json' on the config of the request, so xhr was dropping the response before it ever got back to Angular since the response was not valid json.

Removing responseType: 'json' from the $http (or $resource in your case) request config fixed it for me.

like image 137
Jeff Sheets Avatar answered May 20 '26 13:05

Jeff Sheets