简体   繁体   English

Aurelia http.get 不适用于 Firefox

[英]Aurelia http.get not working with Firefox

I am using the aurelia http.get and it works with IE and Chrome but Firefox throws an exception 'SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data'.我正在使用 aurelia http.get,它适用于 IE 和 Chrome,但 Firefox 抛出异常“语法错误:JSON.parse:JSON 数据的第 1 行第 1 列出现意外字符”。

When I console.log the return in Firefox it has tags on it as such,当我在 Firefox 中 console.log 返回时,它上面有标签,

 <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">
    [{"ID":1,"Name":"Bob",...}]
 </string>

This is straight from the API call.这直接来自 API 调用。

I got an answer in the Aurelia Gitter.我在 Aurelia Gitter 中得到了答案。 The issue was that Firefox defaults http.get request to xml and you have to configure the httpClient to expressly ask for json.问题是 Firefox 将 http.get 请求默认为 xml,您必须配置 httpClient 以明确请求 json。

httpClient.configure(config => {
    config.withHeader('Content-Type', 'application/json');
});

That solved my issue.那解决了我的问题。 Not sure why Firefox defaults to XML.不知道为什么 Firefox 默认使用 XML。 The controller even said to JsonConvert.Seralize(content) on return but Firefox didn't care.控制器甚至在返回时对 JsonConvert.Seralize(content) 说,但 Firefox 并不关心。 IE and Chrome work fine. IE 和 Chrome 工作正常。 Thanks @apawsey for helping me understand the issue.感谢@apawsey 帮助我理解这个问题。

Dont have enough rep to comment.没有足够的代表发表评论。 It would help if you posted ur http.get code.如果您发布您的 http.get 代码会有所帮助。 U are obviously getting your data but the format seems wrong (at least for Firefox).您显然正在获取您的数据,但格式似乎错误(至少对于 Firefox)。 I suggest u read on the docs and find how to set the type of data being sent in the http call.我建议您阅读文档并找到如何设置在 http 调用中发送的数据类型。 I think other browsers figure that out for themselves but Firefox seems to be lost我认为其他浏览器自己解决了这个问题,但 Firefox 似乎丢失了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM