LPology / Simple-Ajax-Uploader

Javascript file upload plugin with progress bar support. Works in all major browsers, including IE7+, Chrome, Firefox, Safari, and Opera. No dependencies - use it with or without jQuery.
995 stars 267 forks source link

IE9 causing JSON to download #73

Closed mattdesl closed 8 years ago

mattdesl commented 10 years ago

When I try this on IE9 it is treating the result as a download. It pops up as "Do you want to open or save uploadd9021494912.json" instead of continuing the callbacks through JS.

Settings:

            url: ...
            name: 'file',
            method: "POST",
            multipart: true,
            data: {
                ...
            },
            responseType: 'json',
            allowedExtensions: ['jpg', 'jpeg', 'png', 'gif'],
            maxSize: 15024, // kilobytes
phatterism commented 9 years ago

I'm having the same issue. Is there any solve for this? I even tried to set the responseType to "text/html" or "text/plain" and no luck. My service is returning JSON and IE9 wants to download the response.

LPology commented 9 years ago

Make sure that you're returning JSON from the server with Content-Type of text/html. That's almost certainly the issue.

Check the response headers in the console to find out the Content-Type and let me know what you see.

phatterism commented 9 years ago

OK that does work now (it doesn't ask to download it anymore), however, for IE9 the onError handler gets called, not the onComplete. I set the responseType to "text/html" when I'm setting it up. Do I have to execute some other functions just for IE9?

LPology commented 9 years ago

Sorry for the delay.

Do you mind posting your code for me to take a look at?

aphillipo commented 9 years ago

I get exactly this same issue. I have a feeling it's something to do with Flask though.

ingro commented 9 years ago

Got the same problem too, if I set the response type to application/json IE 8 and 9 ask to download a .json file, while if I set the response type to text/html, on all the browsers, it triggers both the onComplete and onError callback :(

Here's the code:

uploader = new ss.SimpleUpload({
    button: 'upload-btn',
    url: '/upload_img',
    name: 'img',
    allowedExtensions: ['jpg', 'jpeg', 'png'],
    maxSize: 1024,
    onComplete: function(filename, response) {
        alert(response.message);
    },
    onError: function(filename, errorType, status, statusText, response) {
        alert('Unable to complete the upload process!');
    }
});

The result is that I see before the first alert (with undefined content) and then the one inside onError callback.

Moreover if I set `responseType: 'json'' in the uploader config, the response is correctly parsed and it yells the right content on the 'onComplete' callback, but it triggers the 'onError' callback anyway :(

In debug mode I got this messages:

[Uploader] Commencing upload using multipart form
[Uploader] Server response: {"message":"Image uploaded!"}
[Uploader] Upload failed: -1 reponse is not defined

Any tips?