json xhr response opens a download file popup window

前端 未结 5 1709
孤街浪徒
孤街浪徒 2021-02-04 08:09

For one of our ajax request (with a .json response) some of our clients have complained that they are seeing a \"File Download\" prompt asking the user to download the .json res

5条回答
  •  心在旅途
    2021-02-04 08:36

    Not sure if you found a solution, but I had a similar problem where IE tried to download any JS responses. To fix it, I had to ensure that format.html appears above format.js in the response block:

    def index
    
      # ...
    
      respond_to do |format|
        # html must be above js, otherwise IE will try to download the JS
        format.html
        format.js
      end
    end
    

    Hope this helps.

提交回复
热议问题