Loading ...
Sorry, an error occurred while loading the content.
 

Connect -> response problem and solution: accented characters

Expand Messages
  • wally_gropius
    Hi, Wanted to post/solve a little problem I had. I tested the simplest connection manager using YUI connect api: /*BEGIN CODE*/ var responseSuccess =
    Message 1 of 6 , Apr 25, 2006
      Hi,

      Wanted to post/solve a little problem I had.

      I tested the simplest connection manager using YUI connect api:

      /*BEGIN CODE*/

      var responseSuccess = function(o){

      alert(o.responseText);

      }

      var responseFailure = function(o){

      alert("Failure!");



      }

      var callback =
      {
      success:responseSuccess,
      failure:responseFailure

      }

      function send() {

      YAHOO.util.Connect.setForm("formCourriel");

      var cObj = YAHOO.util.Connect.asyncRequest (
      'POST',

      'http://localhost/eclipse/sarbacane/web/TESTS/Francois/serveur.php',
      callback
      );


      }

      /*END CODE*/

      The php script basically echos back error messages if one the fields
      is empty.

      Whenever the last character of the message string is an accented
      character ('é' is a very common terminaison in French), IE and IE only
      fails the above Javascript with this error code (taken from the
      infamous "debugging" popup):

      Error: System Error: -1072896748

      No problem in FF, though none of the accented character does show up
      in the alert popup I set up.

      Ahh the wonderful world of encoding...

      I finally succeeded in my modest endeavor by using the utf8_encode()
      function of PHP.

      Shouldn't YUI catch this exception?


      François (with a 'ç')
    • webmaster_kaan
      You can try something like that : $ligne) { $encoded_post[$key]= stripslashes(utf8_decode($ligne)); } $_POST = $encoded_post;
      Message 2 of 6 , Nov 21, 2006
        You can try something like that :

        <?php
        foreach ($_POST as $key => $ligne)
        {
        $encoded_post[$key]= stripslashes(utf8_decode($ligne));
        }
        $_POST = $encoded_post;
        ?>

        PS : Ton post date d'avril mais ça peut servir à quelqu'un d'autre....
        J'ai aussi pas mal galéré ;o)
      • wurstfromhell
        As both solutions take into account that one is able to change the result from the server, I d like to know how to circumvent this encoding problem with yui.
        Message 3 of 6 , Apr 19, 2007
          As both solutions take into account that one is able to change the
          result from the server, I'd like to know how to circumvent this
          encoding problem with yui.

          Maybe someone already made a workaround for this while using yui?

          Regards.
        • tssha
          ... ... With XMLHttpRequest, all responseText values are to be UTF-8. Other charsets are not supported. Since Connection Manager implements XHR, this
          Message 4 of 6 , Apr 19, 2007
            --- In ydn-javascript@yahoogroups.com, "wally_gropius"
            <francois.x.hetu@...> wrote:
            >

            <snip>

            > No problem in FF, though none of the accented character does show up
            > in the alert popup I set up.
            >
            > Ahh the wonderful world of encoding...
            >
            > I finally succeeded in my modest endeavor by using the utf8_encode()
            > function of PHP.
            >
            > Shouldn't YUI catch this exception?

            With XMLHttpRequest, all responseText values are to be UTF-8. Other
            charsets are not supported. Since Connection Manager implements XHR,
            this behaviour is intended.

            Regards,
            Thomas
          • Satyam
            From PHP I have the following function which precedes any response from the server side: function setHeader() { header( Cache-Control: no-cache,
            Message 5 of 6 , Apr 19, 2007
              From PHP I have the following function which precedes any response from the
              server side:

              function setHeader() {
              header('Cache-Control: no-cache, must-revalidate'); // HTTP/1.1
              header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
              header('Content-type: text/html; charset=iso-8859-1');
              }

              The first two deals with caching, so nothing gets cached and the third with
              the charset. Of course, you can accept the defaults and encode your
              characters with it, or change it as above. My web is in Spanish and it has
              no problem with accents: I am able to send, lets say, 'á' instead of
              'á' with no problem.

              Satyam

              ----- Original Message -----
              From: "wurstfromhell" <freecycle.5.l0dy@...>
              To: <ydn-javascript@yahoogroups.com>
              Sent: Thursday, April 19, 2007 1:55 PM
              Subject: [ydn-javascript] Re: Connect -> response problem and solution:
              accented characters


              > As both solutions take into account that one is able to change the
              > result from the server, I'd like to know how to circumvent this
              > encoding problem with yui.
              >
              > Maybe someone already made a workaround for this while using yui?
              >
              > Regards.
              >
              >
              >
              >
              >
              >
              >
              > Yahoo! Groups Links
              >
              >
              >
              >
              >
              > --
              > No virus found in this incoming message.
              > Checked by AVG Free Edition.
              > Version: 7.5.446 / Virus Database: 269.5.4/768 - Release Date: 19/04/2007
              > 5:32
              >
              >
            • Caridy Patiño Mayea
              Hi guys: For a long time, I was dealing with this problem (spanish encoding), currently I m solving it in the backend (PHP), every AJAX request will be encoded
              Message 6 of 6 , Apr 19, 2007
                Hi guys:

                For a long time, I was dealing with this problem (spanish encoding),
                currently I'm solving it in the backend (PHP), every AJAX request will
                be encoded in "UTF-8" before the echo (you can use the buffer hook to
                management of the backend result before sending it to the browser):

                // $isAjaxRequester - true if the request was thru ajax
                // $content - XHTML result

                if ($isAjaxRequester) {
                if (function_exists('iconv'))
                $result = iconv("ISO-8859-1", "UTF-8", $content);
                elseif (function_exists('mb_convert_encoding'))
                $result = mb_convert_encoding($content, "UTF-8", "ISO-8859-1");
                }
                echo ($result);

                Tip: iconv & mb_convert_encoding, both implement the same
                functionality, but iconv it's a PHP add-on...

                This code segment solve all my problems with the encoding, you can see
                it in action here:
                http://www.b2vip.com/index.php (developed over PHP and YUI, not ready yet)

                Regards
                Caridy (caridy at gmail.com)
                http://bubbling.comarq.com/

                --- In ydn-javascript@yahoogroups.com, "Satyam" <satyam@...> wrote:
                >
                > From PHP I have the following function which precedes any response
                from the
                > server side:
                >
                > function setHeader() {
                > header('Cache-Control: no-cache, must-revalidate'); // buHTTP/1.1
                > header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
                > header('Content-type: text/html; charset=iso-8859-1');
                > }
                >
                > The first two deals with caching, so nothing gets cached and the
                third with
                > the charset. Of course, you can accept the defaults and encode your
                > characters with it, or change it as above. My web is in Spanish and
                it has
                > no problem with accents: I am able to send, lets say, 'á' instead of
                > 'á' with no problem.
                >
                > Satyam
                >
                > ----- Original Message -----
                > From: "wurstfromhell" <freecycle.5.l0dy@...>
                > To: <ydn-javascript@yahoogroups.com>
                > Sent: Thursday, April 19, 2007 1:55 PM
                > Subject: [ydn-javascript] Re: Connect -> response problem and solution:
                > accented characters
                >
                >
                > > As both solutions take into account that one is able to change the
                > > result from the server, I'd like to know how to circumvent this
                > > encoding problem with yui.
                > >
                > > Maybe someone already made a workaround for this while using yui?
                > >
                > > Regards.
                > >
                > >
                > >
                > >
                > >
                > >
                > >
                > > Yahoo! Groups Links
                > >
                > >
                > >
                > >
                > >
                > > --
                > > No virus found in this incoming message.
                > > Checked by AVG Free Edition.
                > > Version: 7.5.446 / Virus Database: 269.5.4/768 - Release Date:
                19/04/2007
                > > 5:32
                > >
                > >
                >
              Your message has been successfully submitted and would be delivered to recipients shortly.