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:
$(document).ready(function(){
$.ajax({
url: url_string,
dataType: "json",
success: function(response){
alert('all is well');
},
error: function(request, status, error){
alert(request);
alert(status);
alert(error);
}
});
});
I am sure that the server is sending JSON response but IE8 treats it as file and brings up download popup box. But the same process works fine for FF and Chrome. This still happens when i replace json to jsonp in dataType
But it always enters into error callback method.
My json response body consists of a string with html tags too.
Any idea why is this happening?
Thanks
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/
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With