jQuery Ajax在Internet Explorer上不起作用 [英] Jquery Ajax doesn't work at Internet Explorer
问题描述
当我使用放在Internet Explorer 9上的jQuery ajax时,我正在响应正文中获取数据,但是它没有传递给成功函数.我该如何运作?
When I use jQuery ajax put at Internet Explorer 9, I am getting data at response body however it doesn't pass into success function. How can I make it work?
示例:
...
$.ajax({
async : false,
type: 'PUT',
contentType: 'application/json',
url: updateUrl,
data: JSON.stringify(model),
dataType: 'json',
success: function(data) {
console.log("Here!");//it comes here
console.log(data);//it logs undefine at ie, firefox and etc is logging data
r = resultResponse(data);
},
error: function(data) {
try {
r = error($.parseJSON(data.responseText));
} catch (err) {
//Handle error
}
}
});
...
我调试了网络,发现响应正文为:
I debugged network and see that response body is:
{"message":"Connection is successful","status":"success"}
但是在Internet Explorer的成功功能中未定义数据.
However data is undefined at success function at Internet explorer.
有什么想法吗?
PS 1:很奇怪,当我从服务器发送数据而未设置响应头的内容类型时,它起作用吗?
PS 1: It is weird that when I send data from server without setting content type for response header it works?
PS 2:我的响应标题如下:
Key Value
Response HTTP/1.1 200 OK
Server Apache-Coyote/1.1
Content-Type application/json;charset=UTF8
Transfer-Encoding chunked
Date Thu, 02 Aug 2012 15:50:44 GMT
推荐答案
从输出中可以看到,我的字符集是UTF8而不是UTF-8.问题是在服务器端.
As seen at output my charset was UTF8 instead of UTF-8. The problem was that at server side.
这篇关于jQuery Ajax在Internet Explorer上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!