Don't you love when explorer express its griefs in such a clear and helpful way?
I was putting the last touches to the new "Search place" code, and it was working beautifully in Firefox and in Explorer, when I faced a problem in Safari. The query to the database that retrieves the name of places that match the user search came back with the accents garbled!
Safari thought the received page, that I was retrieving with XMLHttpRequest behind the scenes, was encoded in ISO-8859-1 (or most probably, -15) when I was serving it in UTF-8.
Fair enough, I just have to put the header "Content-Type: text/plain; charset=utf8" in the reply, and sure enough, Safari was now working like a charm.
But then, the search stopped working at all in Internet Explorer! I was getting a weird error in the status bar:
Explorer system error: -1072896658
This thing popped when I tried to access the responseText of the request object. After I googled a bit this error code, I found that it was due to the XMLHttpRequest control receiving a reply on an unknown encoding. Please guys, next time put a message like:
XMLHttpRequest requested document was in the unknown "utf8" encoding. See the list of accepted encodings.
It turns out the charset should be UTF-8, and not utf8. Fixed it, and now it is happily working on these 3 browsers.
Update: Attentive reader Johan Sundström pointed out that I was missing the "text/plain; charset=" part on the Content-Type. I should really double check my blog entries before posting them.
Shouldn't that rather be Content-Type: text/plain; charset=UTF-8 (or perhaps text/javascript, depending on the content payload)?
ReplyDeleteHi Johan,
ReplyDeleteyes, it should be Content-Type: text/plain; charset=UTF-8, thank you for the catch! I wrote this entry in a hurry and I missed it completely.
Regards,
Thank the moons for this post. After looking for about 30 mins, this is the first page I've found on this subject that explains in plain english exactly what is causing the problem, and how to fix it. In my case it only appears to occur on a Linux server (I've tried it on two other IIS servers and they worked fine - unfortunately, they're not my production servers). Thanks Joaquín. I'll try it out tonight. *fingers crossed*
ReplyDeleteBless you for this post!
ReplyDeleteIt was just encoding!
So, XMLHttpRequest accepts UTF-8... But the rest of the page in other encoding....Does browser convert data from UTF-8 into another encoding?
Hi,
ReplyDeleteYes, indeed, the exception comes from mlang.dll, I guess that when it tries to do the conversion.
But I have not really tested it, as all my pages are in UTF-8, so I don't really need any conversion. If you are using ISO latin 1, it's also accepted by XMLHttpRequest, but again, you should be extremelly careful with the name you give the encoding (respect uppercase characters, hyphens, ...). For iso latin 1, the charset must be ISO-8859-1
Cheers,
Funny captcha ... and great tip, thank you for saving me from my last two hours of frustation. :)
ReplyDeleteThis article saved me tons of time. I was about to give up. Thanks a lot.
ReplyDeletePhew... unlike the former commenters, I have already spent two (!) days over TCP dumps of http requests from both Firefox and MSIE.
ReplyDeleteI was looking for some hint why on earth IE falied where Firfo just worked. And then I noticed the supid "error big negative number", nicely tucked away in a try{} catch{} block.
Going to have someone change the apache conf - glad that finally there *is* an explanation - thanks a million!
Oh, and by the way, if you need dumps of your tcp traffic, tcpflow is a nice command line utility (compiles fine on Mac OSX).
Thanks for that concise description of the problem. I hope MSIE would be that verbose... =) For your general amusement: In our current setup we use an Oracle Application Server which does not only send different default encoding headers on different platforms, it even send ISO-8859-1 as "ISO-8859_1" (note the underscore) which wrecked the pages when requested via AJAX, but not when requested directly. You have to manually set the content type in your servlet or JSP or whatever you are using.
ReplyDeleteThe Exact command is:
ReplyDeletehttp_request.setRequestHeader('Content-type', 'text/plain;charset=UTF-8;');
where http_request is instance of XMLHttpRequest object.
Thank you!
ReplyDeleteThis post saved my nerves :)
It was just encoding, damn!
THANK YOU MAN!!!!!! It was the encoding.... i had serious troubles with russian language pages (hehehheehe) :)
ReplyDeleteYou can set the content-type with php:
ReplyDeleteAt line 1 of your requested file with XMLHttpRequest
(change text/html with text/plain if required).
See ya!
Add a file called .htaccess to your websites rootdirectory if you are using apache (or your isp uses apache) and it's delivering the wrong charset (like utf8 instead of utf-8 as IE expects it) with the following content:
ReplyDeleteAddCharset utf-8 .php
(or any other extension that might be useful in your context.
See
http://msdn.microsoft.com/workshop/author/dhtml/reference/charsets/charset4.asp
and
http://www.w3.org/International/questions/qa-htaccess-charset
for more information on character encoding issues!
throughs an error System error 1072896658
ReplyDeleteI have declared the object as
var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
it works for IE version 6.0.2600 but not for IE version 6.0.2800.
Pls help me
i coudnlt find out what this error means.
Joaquin,
ReplyDeleteThank you very much for the excelent post... It make my day.
I am form Argentina, greetings.
I have translated the solution to spanish
Regards.
Español/Spanish:
Problema del IE6 (Internet Explorer 6) Error del sistema -1072896658,:
Es muy probable que la página que esté llamando el JavaScript, tenga mal la codificación, en vez de "UTF8" hay que usar "UTF-8".