[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Javascript does not recognize character encoding after jquery loads a php

Posted on 2010-09-21
6
Medium Priority
?
1,848 Views
Last Modified: 2013-12-13
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
Comment
Question by:CodedK
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 33732209
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
 
LVL 16

Author Comment

by:CodedK
ID: 33745407
Hi DaveBaldwin

Any solutions ? Or some trick to bypass this... To force js to act as it should?
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 33746217
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
Technology Partners: 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!

 
LVL 16

Author Comment

by:CodedK
ID: 33746599
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
 
LVL 84

Accepted Solution

by:
Dave Baldwin earned 2000 total points
ID: 33747023
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
 
LVL 16

Author Comment

by:CodedK
ID: 33755496
Thanks.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question