So there's an xml document I'm trying to download and display the contents of that starts off like this:
<?xml version="1.0" encoding="WINDOWS-1251"?>
How am I meant to deal with this? It seems that unless you tell `xmlhttprequest` the encoding, it downloads it as UTF8 and then you get all sorts of rubbish characters. i can get round this by setting `overrideMimeType('text/plain; charset=windows-1251')` in the xmlhttprequest but in general if I don't know what type the document is going to be (and usually I don't), it looks like I'd have to read the content type (as that appears to be correct in the header) and then re-download the document.
Surely there must be a simpler way of doing this? It's not like I can know the character encoding until I've downloaded the file
XML with non default encoding Topic is solved
Moderators: FranklinDM, Lootyhoof
-
- Lunatic
- Posts: 395
- Joined: 2014-05-10, 18:19
- Location: UK
-
- Lunatic
- Posts: 395
- Joined: 2014-05-10, 18:19
- Location: UK
Re: XML with non default encoding
Damn. I can't edit the post now.
Found after some searching it doesn't like me doing responseType = text, which I was doing because, if you don't, then, for reasons known only to mozilla, the browser attempts to parse the returned text as xml even if you get an error back from the server. And then it drivels into the browser console.
I thught maybe it had been cleaned up but no such luck
Found after some searching it doesn't like me doing responseType = text, which I was doing because, if you don't, then, for reasons known only to mozilla, the browser attempts to parse the returned text as xml even if you get an error back from the server. And then it drivels into the browser console.
I thught maybe it had been cleaned up but no such luck
Re: XML with non default encoding
Sorry but if you do an "xmlhttprequest", did you expect the response to be parsed in any way other than XML by default?
"Sometimes, the best way to get what you want is to be a good person." -- Louis Rossmann
"Seek wisdom, not knowledge. Knowledge is of the past; wisdom is of the future." -- Native American proverb
"Linux makes everything difficult." -- Lyceus Anubite
"Seek wisdom, not knowledge. Knowledge is of the past; wisdom is of the future." -- Native American proverb
"Linux makes everything difficult." -- Lyceus Anubite
-
- Lunatic
- Posts: 395
- Joined: 2014-05-10, 18:19
- Location: UK
Re: XML with non default encoding
in the case of the server saying there was a problem I don't expect it to attempt to attempt to parse the response text no. It seems rather a waste of time to say the least.
Re: XML with non default encoding
Since you're using a custom request, the server's response content (e.g. application server) may just as well be an XML. An error page's content can be anything the server wishes.
Any http server should also send back a content-type header along with their 40x or 50x pages, which you should check in your XHR dialogue with the server.
Any http server should also send back a content-type header along with their 40x or 50x pages, which you should check in your XHR dialogue with the server.
"Sometimes, the best way to get what you want is to be a good person." -- Louis Rossmann
"Seek wisdom, not knowledge. Knowledge is of the past; wisdom is of the future." -- Native American proverb
"Linux makes everything difficult." -- Lyceus Anubite
"Seek wisdom, not knowledge. Knowledge is of the past; wisdom is of the future." -- Native American proverb
"Linux makes everything difficult." -- Lyceus Anubite
-
- Lunatic
- Posts: 395
- Joined: 2014-05-10, 18:19
- Location: UK
Re: XML with non default encoding
After a lot of digging around I'm getting the results I want by requesting an 'arraybuffer' response and decode that using TextDecode.