0

How can I post files using AJAX? Now I'm using formData:

    $("#image_upload").change(function() {

        var $form = $(this).closest('form');
        $form.append('<div class="loading-overlay"><div class="loading-overlay__gif"><img src="/images/preloader.gif" class="loading-overlay__gif" /></div></div>');

        $('#photo-choice-error').remove();

        var formData = new FormData();
        formData.append('image', $(this)[0].files[0]);
        // ...
    });

But it doesn't work in some browsers, especially in IE8 and IE9. What can I do instead?

ozahorulia
  • 9,798
  • 8
  • 48
  • 72

1 Answers1

1

I don't think IE 8/9 have support for FormData. AFAIK FormData is available from IE 10.

You could instead try using JQuery Forms, which works on IE 8 onwards.

Srikanth Venugopalan
  • 9,011
  • 3
  • 36
  • 76
  • I thought about that, but in different cases I need to send different parts of my form. And I couldn't find a solution to do that with forms plugin. Did you? – ozahorulia Apr 28 '13 at 14:58
  • I don't think I realize your use cases, but surely you could append elements using `$('#formid').append()`. In case you want your form to be immutable, you could `clone` your form and submit it after appending elements? – Srikanth Venugopalan Apr 28 '13 at 15:02
  • It's not about apending elements to the form. In my case, I need to send only one of all inputs, and then - all onother except that first one. – ozahorulia Apr 28 '13 at 16:52