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

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


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


I'we read this post hoping it would solve the problem I had came across and that had to do with utf8 conversions.

In my case it turned out that the server engine (node.js) calculating the Content-length of the data with the data considered to be raw and not utf8, thus two character extended chars in uft8 was calculated as if they where one char resulting in the server sending one character too little.

See what I did to solve it here: Not well formed Json when sending to CouchDB


I know this is an old post but I had this problem recently and I'd like to contribute just in case someone else has the same problem.I'm using PHP but I'm sure there's an option on every serverside language. It was just a couple of things:

  1. Make sure you're sending the right headers on your ajax response by adding header('Content-Type: text/html; charset=utf-8'); This must be your first line. If you have any errors saying that headers have been sent already or something like that is because somewhere in your code you are outputing an extra space or something before sending the header so check your code.

  2. When you build your response in your server, make sure you convert all your chars to the correspondig HTML char using echo htmlentities($your-string, null, 'utf-8); Because even after telling IE that you are sending utf-8 data, it seems like IE forgets that or it doesn't simply assume anything so adding this to your code will ensure the right output.

Thanks all for your help.