angularJS $ HTTP不剥离preFIX [英] angularJS $http not stripping off prefix
问题描述
根据本文档,AngularJS会剥去preFIX )]}',\\ n
中的JSON响应。我送我的preFIX JSON响应我的JSON响应,但AngularJS没有剥离的preFIX和跨preting的结果。任何想法?谢谢你。
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.
我发送的响应从回弹描述<一个href=\"http://stackoverflow.com/questions/25249113/$p$pfixing-json-in-mappingjackson2httpmessageconverter/25249477#25249477\">here.而且它发送的preFIX JSON响应)]}',\\ n
。在AngularJS,我需要检索的值:
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/', {..});
和中签回叫功能:
var successQuestions = function (q) {
$rootScope.q1 = q.question1;
};
我期待q JSON是由AngularJS为JSON PTED妥善间$ P $,但事实并非如此。
I am expecting q JSON to be properly interpreted by AngularJS as a JSON but it is not.
推荐答案
我有同样的问题,并注意到XHR对象认为反应是零。对我来说,问题是,我有的responseType:JSON
的请求的配置,所以XHR一度下探响应之前它曾经得到回角,因为反应不是有效的JSON。
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.
删除 responseTyp的:JSON
从$ HTTP(或$在您的案件资源)的要求配置固定为我
Removing responseType: 'json'
from the $http (or $resource in your case) request config fixed it for me.
这篇关于angularJS $ HTTP不剥离preFIX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!