Results 1 to 8 of 8

Thread: Dynamic Ajax Content : charset problem

  1. #1
    Join Date
    Jul 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Dynamic Ajax Content : charset problem

    1) Script Title: Dynamic Ajax Content

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...jaxcontent.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.

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Jul 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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..

  4. #4
    Join Date
    Jul 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by drannh View Post
    1) Script Title: Dynamic Ajax Content

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...jaxcontent.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.

  5. #5
    Join Date
    Jul 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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 with conversions. Most of the french guys are staying in ISO, that's much more simple

    Seb.

  6. #6
    Join Date
    Jul 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    That sounds nice. It sounds messy but if it will get the job done maybe I can use the script.

  7. #7
    Join Date
    Jul 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Here it is :

    In the JS file, change by this :
    Code:
    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) :
    Code:
    <?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

  8. #8
    Join Date
    Jul 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I'll give it a go. Thanks.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •