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

Reply via email to