在GET上期待JSON结果时,Angularjs $ http"XML解析错误:找不到元素位置"错误

why*_*ite 8 ajax json angularjs

当我提交angularjs $http GET调用时,我收到XML解析错误.

$ http呼叫代码段是:

$http({
    method: 'GET',
    url: "myapp/api/items" + itemId
 });
Run Code Online (Sandbox Code Playgroud)

错误是:

XML Parsing Error: no element found Location: moz-nullprincipal:{f191853f-5581-b049-b83f-5f4b69211adb} Line Number 1, Column 1:
Run Code Online (Sandbox Code Playgroud)

返回的数据是JSON.如果我将URL放在浏览器中,则提交请求并且响应数据在浏览器中成功返回.

我尝试在调用中添加responseType: 'json'(和responseType: 'application/json')但$http没有成功.(我引用了angularjs http doc中的Usage部分来确定如何配置调用.)

有没有办法可以强制将响应数据识别为json以避免该错误?

Rob*_*res 2

如果您使用的是 Mozilla Firefox,请安装 firebug 并尝试在“网络”面板或“控制台”面板中检查 http GET。

在标头选项卡中,您可以检查正在发送和接收的内容类型。也许问题出在服务器端响应的内容类型中。