seroth
seroth

Reputation: 647

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'.

When I console.log the return in Firefox it has tags on it as such,

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

This is straight from the API call.

Upvotes: 1

Views: 228

Answers (2)

seroth
seroth

Reputation: 647

I got an answer in the 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.

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

That solved my issue. Not sure why Firefox defaults to XML. The controller even said to JsonConvert.Seralize(content) on return but Firefox didn't care. IE and Chrome work fine. Thanks @apawsey for helping me understand the issue.

Upvotes: 1

Gilbert Nwaiwu
Gilbert Nwaiwu

Reputation: 728

Dont have enough rep to comment. It would help if you posted ur http.get code. U are obviously getting your data but the format seems wrong (at least for Firefox). I suggest u read on the docs and find how to set the type of data being sent in the http call. I think other browsers figure that out for themselves but Firefox seems to be lost

Upvotes: 0

Related Questions