Angularjs $ http"XML解析错误:找不到元素位置"期望GET上的JSON结果时出错 [英] Angularjs $http "XML Parsing Error: no element found Location" error when expecting JSON results on GET

查看:147
本文介绍了Angularjs $ http"XML解析错误:找不到元素位置"期望GET上的JSON结果时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

When I submit an angularjs $http GET call I receive an XML parsing error.

$ http呼叫代码段为:

The $http call code snippet is:

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

错误是:

XML Parsing Error: no element found Location: moz-nullprincipal:{f191853f-5581-b049-b83f-5f4b69211adb} Line Number 1, Column 1:

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

The data being returned is JSON. If I put the URL in a browser then the request is submitted and the response data comes back successfully in the browser.

我尝试将responseType: 'json'(和responseType: 'application/json')添加到$http调用中,但没有成功. (我在 angularjs http doc中引用了用法"部分确定如何配置呼叫.)

I tried adding responseType: 'json' (and responseType: 'application/json') to the $http call with no success. (I referenced the Usage section in angularjs http doc to determine how to configure the call.)

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

Is there a way I can force the response data to be recognize as json to avoid that error?

推荐答案

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

If you are using Mozilla Firefox, install firebug and try to inspect the http GET in the Net panel or in the Console panel.

在标题标签中,您可以检查正在发送和接收的内容类型.也许问题出在服务器端响应的内容类型上.

In the headers tab you can check the Content-Types being sent and received. Maybe the problem is in the server-side response's content-type.

这篇关于Angularjs $ http"XML解析错误:找不到元素位置"期望GET上的JSON结果时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆