Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Firefox 13.0.1 and IE7+ work fine with the JSON file on the server. Yet, FF14 returns 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.js.

And when you visit this website (a testing website of mine), http://lifelearning.x10.mx/test/php_slides.html (you can view the codes there) and 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.

like image 545
Tin Amaranth Avatar asked Jan 17 '23 00:01

Tin Amaranth


1 Answers

The content type & character encoding can be set with an HTTP header. The header you probably want is:

Content-type: application/json; charset=UTF-8

If you are serving up json data from php you can add this header with the header() command. If you are using apache, you can use a .htaccess file with these lines:

AddType application/json .json
AddCharset UTF-8 .json
like image 130
fuzic Avatar answered Jan 25 '23 22:01

fuzic