PDA

View Full Version : Dynamic Ajax Content : charset problem



drannh
07-31-2007, 04:58 PM
1) Script Title: Dynamic Ajax Content

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm

3) Describe problem:
I'm using charset ISO-8859-1 on my site, because of french language with cars as é à ç , ..
When I use Ajax, I usually convert utf-8 to ISO in the called PHP script. But with this script Dynamic Ajax Content, there is no PHP, so I cannot convert, so it displays "?" or "�" in place of my caracters with accents.
Is it a way to convert it in the JS part ? or add a magic trick via a PHP script ?

Thanks for your help !
Sébastien.

Twey
07-31-2007, 05:13 PM
If I were you, I'd use UTF-8 for both pages. ISO-8859-1 offers no advantage over UTF-8, and of course UTF-8 is far more flexible and allows multi-byte characters too where necessary.

drannh
07-31-2007, 06:32 PM
Well, I would have prefered another solution..
I have to change all the website.
I did some quick tests, ouch... i see problems and problems..

Fizzgigg
08-01-2007, 12:31 PM
1) Script Title: Dynamic Ajax Content

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm

3) Describe problem:
I'm using charset ISO-8859-1 on my site, because of french language with cars as é à ç , ..
When I use Ajax, I usually convert utf-8 to ISO in the called PHP script. But with this script Dynamic Ajax Content, there is no PHP, so I cannot convert, so it displays "?" or "�" in place of my caracters with accents.
Is it a way to convert it in the JS part ? or add a magic trick via a PHP script ?

Thanks for your help !
Sébastien.

Im having the same problem with Swedish pages. De fault page looks fine but all other pages has this problem.

drannh
08-01-2007, 01:20 PM
Hey Fizz,

I have solved the problem yesterday by adding a PHP step, that let me do the conversion to ISO + get the source code of the html file and send it back to JS script. As I'm not at home for now, I can't give you any code, but I will later.. maybe tonight or tomorrow.

To change everything in UTF-8, that's easy for english language, but when you got accentued cars, this is :eek: with conversions. Most of the french guys are staying in ISO, that's much more simple :cool:

Seb.

Fizzgigg
08-01-2007, 01:29 PM
That sounds nice. It sounds messy but if it will get the job done maybe I can use the script. :)

drannh
08-02-2007, 06:43 AM
Here it is :

In the JS file, change by this :

page_request.open('POST', 'YouPhpScript.php', true);
page_request.send("url="+url);


The PHP should look like something like this (I do it from memory) :

<?php
header('Content-Type: text/html; charset=ISO-8859-15');

function getSource($url) {
$file = fopen ($url,"r");
if (!$file) {
return null;
}
$doc = "";
while (!feof ($file))
$doc .= fgets ($file, 1024);
fclose($file);
return $doc;
}

extract($_POST);
$url = htmlentities(utf8_decode($url));
echo getSource($url);

?>

If there are syntax errors, just correct them :p

Fizzgigg
08-02-2007, 07:44 AM
I'll give it a go. Thanks. :)