jQuery Ajax Get Doesn't Pass Received Data Into Success Function at Internet Explorer

☆樱花仙子☆ 提交于 2019-12-11 19:57:19

问题


My question is when I use jQuery ajax get, I am getting data at response body however it doesn't pass into success function. How can I make it work?

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
            }
        }
    });

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:

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?

EDIT: I tried that style:

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

However response header is still:

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


回答1:


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



来源:https://stackoverflow.com/questions/11765363/jquery-ajax-get-doesnt-pass-received-data-into-success-function-at-internet-exp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!