I think there is no way. I've made some experiments with a hex editor
to be sure.

Simple script with $.ajax via post.
data: "test=à"

manually typed in a non UTF-8 script file

Server side script:
if(isset($_POST['test'])){
        $test=utf8_decode($_POST['test']) . ' - ' . $_POST['test'];
        writelog($test);
}

Everywhere full of iso-8859-1:
header('Content-Type: text/html; charset=iso-8859-1');
<meta http-equiv="Content-Type" content="text/
html;charset=iso-8859-1" />


When jQuery post the data to the server script, is write down:
E0 (right char) 20 (space) 2D (-) 20 (space) C3 A0 (strange kind of A)

So at the moment I find nothing else to do other than using utf8_decode
()

I've also try
dataType: "jsonp",
scriptCharset: "iso-8859-1",

with zero results.



On Dec 31 2008, 3:16 pm, Romain Viovi <imp...@gmail.com> wrote:
> Hell yeah, after reading jquery's method $.param, i understood that the
> encodeURIComponent is used to serialize object.
>
> And after reading ECMA spec about this function, I understood that only
> UTF-8 is outputed !
>
> So, I understand that it's perfectly ok to utf8_decode() what I receive
> serverside in an iso context.
>
> I'm not OK to work in all utf-8 context when it's not needed. For
> example, MySQL sorting in utf-8 could be very much more longer in utf-8
> than in ISO.
> I prefer say that, yeah, when you do a project in a special context,
> just do everything in that context.
>
> Thanx for your replies.
> Sorry for my english :)
>
> Alexandre Plennevaux a écrit :
>
>
>
> > did you try playing with the $.ajax scriptCharset option ?
> > see:http://docs.jquery.com/Ajax/jQuery.ajax
>
> > On Wed, Dec 31, 2008 at 1:27 PM, AdrianMG <yens...@gmail.com> wrote:
> >> I am not pretty sure but I think you can work with UTF8 only in AJAX,
> >> but I recommend you work with UTF8 always
>
> >> On Dec 30, 2:09 pm, Romain Viovi <imp...@gmail.com> wrote:
> >>> Hello Everybody,
>
> >>> I'm experiencing some problems with the $.ajax
>
> >>> When sending simple post request, request Headers (logged with firebug)
> >>> are always "application/x-www-form-urlencoded; charset=UTF-8" tagged for
> >>> content-type
>
> >>> see :
>
> >>> Request Headers
> >>> User-Agent      Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; 
> >>> rv:1.9.0.5)
> >>> Gecko/2008120122 Firefox/3.0.5
> >>> Accept  */*
> >>> Accept-Language fr
> >>> Accept-Encoding gzip,deflate
> >>> Accept-Charset  ISO-8859-1,utf-8;q=0.7,*;q=0.7
> >>> Keep-Alive      300
> >>> Connection      keep-alive
> >>> Content-Type    application/x-www-form-urlencoded; charset=UTF-8
> >>> X-Requested-With        XMLHttpRequest
> >>> Content-Length  152
>
> >>> But, i'm always working with iso-8859-1 encoding, my page include
> >>> headers with the good charset, php.ini is set to the good default charset.
>
> >>> So, when i retrieve the $_POST, i've to utf8_decode() cause utf8 datas
> >>> are retrieved and special chars as "é", "à" are not recognised
>
> >>> I think I shouldn't have to do that...
>
> >>> Here's the test.html file :
>
> >>> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
> >>> "http://www.w3.org/TR/html4/loose.dtd";>
> >>> <html>
> >>>     <head>
> >>>         <meta http-equiv="Content-Type" content="text/html;
> >>> charset=ISO-8859-1">
> >>>         <title>Test encoding</title>
> >>>         <script type="text/javascript" language="javascript"
> >>> src="jquery-1.2.6.js">
> >>>         </script>
> >>>     </head>
> >>>     <body>
> >>>         <form enctype="application/x-www-form-urlencoded;
> >>> charset=ISO-8859-1" action="test.php" name="search"  method="post">
> >>>             <input id="qry" name="qry" value="" type="text" /><input
> >>> type="button" onclick="send();" value="ok" />
> >>>         </form>
> >>>         <div id="answers">
> >>>         </div>
> >>>         <script type="text/javascript" language="javascript">
>
> >>>             function send(){
> >>>                 $.ajax({
> >>>                     type: "POST",
> >>>                     url: "./test.php",
> >>>                     contentType: "application/x-www-form-urlencoded;
> >>> charset=iso-8859-1",
> >>>                     data: {
> >>>                         qry: $('#qry')[0].value
> >>>                     },
> >>>                     success: function(data){
> >>>                         $('#answers').empty().append(data);
> >>>                         return;
> >>>                     }
>
> >>>                 });
> >>>             }
> >>>         </script>
> >>>     </body>
> >>> </html>
>
> >>> And the test.php :
>
> >>> <?php
> >>> header("Content-Type: text/html; charset=ISO-8859-1");
> >>> var_dump($_POST);
> >>> ?>
>
> >>> Thanx for the help !
>
> >>> --
> >>> Romain Viovi
> >>> 42 rue Pigalle
> >>> 75009 Paris
>
> >>> +33 6 63 16 90 15
> >>> +33 9 54 40 84 40
>
> >>> romain.vi...@gmail.com
>
> --
> Romain Viovi
> 42 rue Pigalle
> 75009 Paris
>
> +33 6 63 16 90 15
> +33 9 54 40 84 40
>
> romain.vi...@gmail.com

Reply via email to