jQuery Ajax Get不会将接收到的数据传递到Internet Explorer的成功函数中

问题描述:

我的问题是,当我使用jQuery ajax get时,我正在响应正文中获取数据,但是它没有传递给成功函数.我该如何运作?

我正在制作一个ajax放置程序,但是它在ie9上不起作用(在其他浏览器上也可以),因此我将其更改为仅用于测试:

I am making an ajax put but it doesn't work at ie9 (works on other browsers) so I changed it like that just for test:

    $.ajax({
        async : false,
        type: 'PUT',
        contentType: 'application/json',
        url:updateUrl + "?_" + new Date().getTime(),
        data: JSON.stringify(model),
        cache: false,
        dataType: "json",
        dataFilter: function(data) {
            var resp = eval('(' + data + ')');
            return resp;
        },
        success: function(data, status, xhr) {
            alert("success> " + data.property);
            alert(typeof data);
            r = resultResponse(data);
         },
        error: function(data, status, xhr) {
            alert("error> " + data.responseText);
            try {
                r = error($.parseJSON(data.responseText));
            } catch (err) {
                //Handle error
            }
        }
    });

数据警报未定义.我的put数据正确发送,我的服务器端运行良好,并向客户端发送了响应,但是我得到的是undefined而不是data.经过一些测试,我意识到了问题所在:

data is alerting as undefined. My put data is sending correctly, my server side works well and send response to client however I get undefined instead of data. After some tests I realized the problem:

当我在9响应主体捕获网络通信数据包时,就是我想要的.但是成功功能无法处理.如果需要,我可以提供有关服务器的更多信息(当我将数据写入响应而不是在Java上使用jackson json映射器时,我可以使其正常工作-可以正常工作,唯一的区别是响应时未包含工作版本标头: 核心价值 Content-Type application/json; charset = UTF8)

When I capture network communication packets at ie 9 response body is what I want. However success function can not handle it. If needed, I can give more information about my server(I could make it work when I write the data to response instead of using jackson json mapper at Java - it was working and the only difference was that was not included ta working version at response headers: Key Value Content-Type application/json;charset=UTF8 )

我认为问题可以在客户端解决,而不是服务器端. 有什么想法吗?

I think that the problem can be handle at client side, I think not with server side. Any ideas?

我尝试过这种风格:

$.ajax({url: "/url",
  dataType: "text",
  success: function(text) {
    json = eval("(" + text + ")");
    // do something with JSON
  }
}); 

但是响应头仍然是:

键值 内容类型application/json; charset = UTF8

Key Value Content-Type application/json;charset=UTF8

问题是字符集错误.是UTF(而不是UTF-8).

The problem was wrong charset. It was UTF( instead of UTF-8).