IE prompts to open or save json result from server

后端 未结 9 1203
既然无缘
既然无缘 2020-11-29 22:28

Internet explorer in compatibility mode gets the data from the server in an ajax callback method, and pops-up a dialog if I want to save the data or open. How to get rid of

相关标签:
9条回答
  • 2020-11-29 22:42

    Is above javascript code the one you're using in your web application ? If so - i would like to point few errors in it: firstly - it has an additional '{' sign in definition of 'success' callback function secondly - it has no ')' sign after definition of ajax callback. Valid code should look like:

    $.ajax({
            type:'POST',
            data: 'args',
            url: '@Url.Action("PostBack")',
            success: function (data, textStatus, jqXHR) {
                    alert(data.message);
                }
        });
    

    try using above code - it gave me 'Yay' alert on all 3 IE versions ( 7,8,9 ).

    0 讨论(0)
  • 2020-11-29 22:53

    Even though it's not supposedly the correct way, setting the content type to text/html made IE deal with this correctly for me:

    return Json(result, "text/html");
    

    Works in all the version that F12 tools gives you in IE9.

    0 讨论(0)
  • 2020-11-29 22:55

    I faced this while using jQuery FileUpload plugin.

    Then I took a look in their documentation, most exactly in the Content-Type Negotiation section and followed their suggestion for Ruby/Rails.

    render(json: <some-data>, content_type: request.format)
    

    Which fixed the issue for me.

    Quick Explanation: for old IE/Opera versions, this plugin will use an iframe with text/plain or text/html content-type, so if you force the response to json, browser will try download it. Using the same content-type as in the request will make it work for any browser.

    0 讨论(0)
提交回复
热议问题