Jquery Ajax doesn't work at Internet Explorer

佐手、 提交于 2019-12-06 03:17:34

问题


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?

example:

...
    $.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"}

However data is undefined at success function at Internet explorer.

Any ideas?

PS 1: It is weird that when I send data from server without setting content type for response header it works?

PS 2: My response header as follows:

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

回答1:


As seen at output my charset was UTF8 instead of UTF-8. The problem was that at server side.




回答2:


This might be much to ask, but can you try to substitute your full $.ajax call into a $.getJSON? it will be much simpler and easier for the browser to execute, as your problem might be in one of the numerous settings and configurations you made for your ajax call.

keep it as simple as you can:

$.getJSON(updateUrl, JSON.stringify(model), function(data){
    console.log(data);
});

If you need to check up on getJSON, check here



来源:https://stackoverflow.com/questions/11772299/jquery-ajax-doesnt-work-at-internet-explorer

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