-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
When sending JSON back via an iframe transport, IE prompts for download #1795
Comments
@nosykretts Right, setting a response type of 'text/html' will resolve the problem. But it is incorrect to return JSON data as content type text/html for REST clients and browsers that work correctly. The flag would allow server side logic to only use the text/html hack for incompatible IE clients. |
From the Setup guide: Content-Type NegotiationThe file upload plugin makes use of an Iframe Transport module for browsers like Microsoft Internet Explorer and Opera, which do not yet support XMLHTTPRequest file uploads. You can make use of the Accept header to offer different content types for the file upload response. Here is the (PHP) example code snippet for the Accept content-type variation: <?php
header('Vary: Accept');
if (isset($_SERVER['HTTP_ACCEPT']) &&
(strpos($_SERVER['HTTP_ACCEPT'], 'application/json') !== false)) {
header('Content-type: application/json');
} else {
header('Content-type: text/plain');
}
?> |
For java applies equivalent:
|
can you tell me how to get around this in .net/IIS 7? i am not sure where to place the content type =text line |
For MVC users under IIS, do it that way:
|
Can you give an example for rails app as well ? |
Yes, please, I'd like an example for rails too |
For a Rails example, see the Controller section here: https://github.com/blueimp/jQuery-File-Upload/wiki/Rails-setup-for-V6 |
When using the iframe transport fallback for IE browsers, and responding with a JSON object and content type of 'application/json', Internet Explorer will prompt to download the file. Responding with content type 'text/html' resolves the problem, however it is not exactly correct and not something that should be returned for XHR requests or REST clients. I'd like to propose adding a field to the data submitted via iframe transport so that the server can identify those requests and adjust the content type dynamically.
I simply added the following immediately before the bit that copies options.formData (~line 93)
form.append('')
The text was updated successfully, but these errors were encountered: