jsonajaxinternet-explorermultipartform-datajqueryform

IE tries to download json response while submitting jQuery multipart form data containing file


I'm trying to submit a form with a file field in it via jQuery.Form plugin, here's the code:

$('form').ajaxSubmit({
  url: "/path",
  dataType: "json",
  contentType: "multipart/form-data"
...

The server then returns json as a response. Works great in all browsers except IE, which tries to download the response as a file. If I remove the file field from the form, it also works just fine.

I've seen various solutions here and in Google and basically tried almost everything described, including setting enctype for the form via jQuery, but it didn't work.

Any suggestions would be very welcomed.


Solution

  • I have not found a direct solution to this, but I eventually implemented the following workaround: I used dataType: "text" in my ajax settings and then returned plaintext from controller, separating values with ; and parsing them on the client side. That way IE and Forefox stopped trying to download a response.

    I did not find any other way to prevent said behavior other then to return plaintext. I tried returning JSON as plaintext and then parsing it with $.parseJSON, but it didn't work due to some js errors.