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

前端 未结 4 752
情话喂你
情话喂你 2020-12-05 10:42

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,         


        
4条回答
  •  庸人自扰
    2020-12-05 10:49

    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.

提交回复
热议问题