JQuery的AJAX没有发送UTF-8到我的服务器,只有在IE浏览器 [英] JQuery AJAX is not sending UTF-8 to my server, only in IE
问题描述
我送UTF-8,日本的文字,我的服务器。 它工作在Firefox浏览器。我的access.log和标题是:
/阿贾克斯/ Q =%E6%BC%A2%E5%AD%97
接收字符集ISO-8859-1,UTF-8,Q = 0.7,*; Q = 0.7
内容类型application / x-WWW的形式urlen codeD;字符集= UTF-8
Howeer,在IE8,我的access.log说:
/阿贾克斯/ Q =?
由于某些原因,IE8是把我的AJAX调用成问号。为什么!?我加入了scriptCharset和的ContentType根据一些教程,但仍没有运气。
这是我的code:
$。阿贾克斯({
方法:获取,
网址:/ AJAX /,
scriptCharset:UTF-8,
的contentType:应用程序/ x-WWW的形式urlen codeD;字符集= UTF-8,
数据:Q =+查询...
...
})
试着用连接codeURIComponent()编码的查询参数
数据:Q =EN + codeURIComponent(查询)
作为bobince非常正确地指出在他的评论,如果您使用对象表示法将参数传递给ajax的方法,将处理的编码本身。
所以
数据:{Q:查询}
将jQuery的处理编码。
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 ...,
...
})
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 ..
这篇关于JQuery的AJAX没有发送UTF-8到我的服务器,只有在IE浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!