IE8 treats json response as file and tries to download it

前端 未结 3 1662
心在旅途
心在旅途 2021-01-01 20:27

I am using IE8 and I am sending ajax request to on of the url which sends back response as json. The jquery code for the ajax setup is given below:

$(documen         


        
相关标签:
3条回答
  • 2021-01-01 21:09

    Depending on what is sending the json, you have to send it as mime type text. So in rails I had to do this.

        render :text => my_array.to_json
    

    Instead of

        render :json => my_array
    
    0 讨论(0)
  • 2021-01-01 21:09

    I modified the url of your code and used the latest version of JQuery and it runs fine within IE8 for me

    <html> 
    <head>   
      <script src="http://code.jquery.com/jquery-latest.js"></script> 
    </head> 
    <body> 
    <script>  
        $(document).ready(function() {            
        $.ajax({                      
            url: "http://api.flickr.com/services/feeds/groups_pool.gne?id=807213@N20&lang=en-us&format=json&jsoncallback=?",
                        dataType: "json",                      
            success: function(response){                        
                alert('all is well');                      
                alert($.param(response));                 
            },                      
            error: function(request, status, error){                            
                alert(request);                            
                alert(status);                            
                alert(error);
            }          
    });  
    }); 
    </script> 
    </body>
    </html>
    

    There is a known issue as detailed in this answer where IE8 has problems with an extra comma in a result array. Check the contents of the response alert for this.

    0 讨论(0)
  • 2021-01-01 21:13

    I had the same issue and fixed it by setting Content-type = "text/html" in the response header for all IE requests (rather than "application/json")

    I also wrote a blog post about it with some more information: http://blog.degree.no/2012/09/jquery-json-ie8ie9-treats-response-as-downloadable-file/

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