IE prompts to open or save json result from server

后端 未结 9 1242
既然无缘
既然无缘 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: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: , 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.

提交回复
热议问题