• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1902
  • Last Modified:

Javascript does not recognize character encoding after jquery loads a php

Hi.
I have the following problem :

---- ccc.php -----
This file contains the correct header info to display greek.
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-7" />
<script src="js/ccc.js" type="text/javascript"></script>




---- ccc.js -----
Inside this file if i write an alert('Greek characters here') everything will display correctly.
On a click event of a div located in ccc.php I load another php file called renew.php.
On the callback of the load procedure :
       
$('.just_a_div').load('./js/renew.php',function() {
            $.getScript('./js/renew.js');
       }
);


---- renew.php ----
header('Content-Type: text/html; charset=ISO-8859-7');


-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~

Now the problem is that renew.js script... working for renew.php CANNOT display the ISO-8859-7 characters. Its as if it never gets the information from the headers. And display everything with black squares. (possibly utf-8 encoding)


I also tried to use ajax with contentType:
"application/x-www-form-urlencoded;charset=ISO-8859-7"
(solution from stack overflow)

but with no luck.

Thanks for your help.
0
CodedK
Asked:
CodedK
  • 3
  • 3
1 Solution
 
Dave BaldwinFixer of ProblemsCommented:
This question came up before.  Your problem is that javascript uses UTF-8 internally.  AJAX uses javascript.  Javascript will corrupt anything but ASCII and UTF-8.  ASCII is a subset of UTF-8.  While your content header would work with the browser directly, it doesn't matter to javascript.
0
 
CodedKAuthor Commented:
Hi DaveBaldwin

Any solutions ? Or some trick to bypass this... To force js to act as it should?
0
 
Dave BaldwinFixer of ProblemsCommented:
Javascript uses Unicode internally which gets converted to UTF-8 in the browser and you can't change it.  Here's a discussion about it. http://stackoverflow.com/questions/919936/does-javascript-force-specific-charset  I found another article about 'escaping' characters that are not Unicode to make your text pass thru javascript without being screwed up.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
CodedKAuthor Commented:
Thanks for the fast response.
So far i do use escape characters. This is uncomfortable.
Do you know any function to convert this characters from whatever language to an escape char string?

Example :

alert(CHANGE_TO_ESCAPE_CHARS(greek chars here))
0
 
Dave BaldwinFixer of ProblemsCommented:
Here's one article: http://www.zachleat.com/web/2010/03/26/charset/  Here's another: http://capitolacomputing.com/intl_js_charset.htm but I have to point out a problem.  It is one thing to have your page in a particular charset... but javascript internally will handle text as Unicode no matter what your page is using.  Loading text thru AJAX means that javascript reads and writes that text... in Unicode.

Here's a page about conversions: http://www.unicodetools.com/  and PSPad http://www.pspad.com/ will handle UTF-8.

The only way I found to make it work is to do everything in UTF-8.
0
 
CodedKAuthor Commented:
Thanks.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now