JQuery AJAX is not sending UTF-8 to my server, only in IE

ajax, internet-explorer-8, javascript, jquery, utf-8

Solution

Try encoding the query parameter with `encodeURIComponent()`

data:"q="+encodeURIComponent( query )

as bobince very correctly noted in his comment, if you use the object notation to pass parameters to the ajax method it will handle the encoding itself..

so

data:{ q : query }

will make jQuery handle the encoding ..

Problem

I am sending UTF-8, japanese text, to my server. It works in Firefox. My access.log and headers are: ``` /ajax/?q=%E6%BC%A2%E5%AD%97 Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7 Content-Type application/x-www-form-urlencoded; charset=UTF-8 ``` Howeer, in IE8, my access.log says: ``` /ajax/?q=?? ``` For some reason, IE8 is turning my AJAX call into question marks. Why!? I added the scriptCharset and ContentType according to some tutorials, but still no luck. And this is my code: ``` $.ajax({ method:"get", url:"/ajax/", scriptCharset: "utf-8" , contentType: "application/x-www-form-urlencoded; charset=UTF-8", data:"q="+query ..., ... }) ```

Original source