Jump to content

Firefox 14.0.1: returns error when reading a JSON file sent via AJAX


tinfanide

Recommended Posts

I don't know if I have posted this question in a right area here. Yet it's about AJAX and JSON, I treat it as a JavaScript's one. My question is:Firefox 13.0.1 and IE7+ do not return this error message produced by the console when I open the JSON (stored online) file in the browser:

The character encoding of the plain text document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the file needs to be declared in the transfer protocol or file needs to use a byte order mark as an encoding signature. http://lifelearning.x10.mx/test/php_slides.jsLine 20
And when you visit this website (a testing website of mine),http://lifelearning.x10.mx/test/php_slides.htmland scroll your mouse within the div (surrounded by the black border),the texts do not come out expectedlly (which otherwise do in any browsers listed above except FF14). I would like to ask how I can declare the character encoding of a plain text as requested by the FF14 web console. Many thanks in advance.
Link to comment
Share on other sites

I don't know if I have posted this question in a right area here. Yet it's about AJAX and JSON, I treat it as a JavaScript's one.
You realize that AJAX and JSON are part of the Javascript language? As for your issue, perhaps you need to set a Content-Type header.http://www.w3schools.com/ajax/ajax_xmlhttprequest_send.asp and set it to plain/text It would be good if you provided instructions on how to reproduce the issue though, I'm not sure how your form/slide thing is supposed to work.
Link to comment
Share on other sites

A request header wouldn't solve the problem. You need the server to tell the browser what encoding the file is using. If you can't tell the server to send a character set header, you can fix it on the client side using the overrideMimeType() method.

xmlhttp.overrideMimeType("text/plain; charset=UTF-8");

Link to comment
Share on other sites

You realize that AJAX and JSON are part of the Javascript language? As for your issue, perhaps you need to set a Content-Type header.http://www.w3schools...equest_send.asp and set it to plain/text It would be good if you provided instructions on how to reproduce the issue though, I'm not sure how your form/slide thing is supposed to work.
It seems not working.
Link to comment
Share on other sites

A request header wouldn't solve the problem. You need the server to tell the browser what encoding the file is using. If you can't tell the server to send a character set header, you can fix it on the client side using the overrideMimeType() method.
xmlhttp.overrideMimeType("text/plain; charset=UTF-8");

It seems not working.
Link to comment
Share on other sites

Alright, something's wrong here. Can you show the code involved with the XmlHttp request? Edit: I'm lookind at the link to your page.

Edited by Ingolme
Link to comment
Share on other sites

Well, I've checked the page and it works just fine in Firefox 14.I'm just getting an error:

TypeError: codes is nullcodes = codes.replace(/</g,"<");
Link to comment
Share on other sites

Well, I've checked the page and it works just fine in Firefox 14.
The page still doesn't show the texts in mouse scrolling.Mine is Firefox Portable 14.0.1. Does it matter?
I'm just getting an error:
I didn't get the error. On the contrary, I still get the error as stated in my first thread:
The character encoding of the plain text document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the file needs to be declared in the transfer protocol or file needs to use a byte order mark as an encoding signature.
Link to comment
Share on other sites

Unfortunately, I can't help much more if I can't see the error myself.Since the content is JSON, it might be better to use a .json extension rather than .txt

Link to comment
Share on other sites

Unfortunately, I can't help much more if I can't see the error myself.Since the content is JSON, it might be better to use a .json extension rather than .txt
I couldn't track the version of the codes you have seen no error returning and whether that is the same to mine at present.Now my altered codes work in FF14:
// php_slides.js var sJSON, xmlhttp;var ajax = function(action,method,source,async){xmlhttp = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP") ? new ActiveXObject("Msxml2.XMLHTTP") : null ; // I have moved this section before the onreadystatechange function// previously this section was after the onreadystatechange function, which it didn't workxmlhttp.open(method,source,async);xmlhttp.send();// xmlhttp.onreadystatechange = function(){  if (this.readyState == 4 && this.status == 200)  {   sJSON = (String(source).toLowerCase().substr(String(source).length-5,String(source).length)==".json") ? JSON.parse(this.responseText) : (String(source).toLowerCase().substr(String(source).length-4,String(source).length)==".txt") ? this.responseText : null;     action();  }};}

It still returns this error in the console when you use FF14 to browse to php_slides.json, though:

The character encoding of the plain text document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the file needs to be declared in the transfer protocol or file needs to use a byte order mark as an encoding signature.
Edited by Tin
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...