Quantcast
Channel: Sending multipart/formdata with jQuery.ajax - Stack Overflow
Viewing all articles
Browse latest Browse all 15

Answer by Karl Henselin for Sending multipart/formdata with jQuery.ajax

$
0
0

Devin Venable's answer was close to what I wanted, but I wanted one that would work on multiple forms, and use the action already specified in the form so that each file would go to the right place.

I also wanted to use jQuery's on() method so I could avoid using .ready().

That got me to this: (replace formSelector with your jQuery selector)

$(document).on('submit', formSelecter, function( e ) {        e.preventDefault();    $.ajax( {        url: $(this).attr('action'),        type: 'POST',        data: new FormData( this ),        processData: false,        contentType: false    }).done(function( data ) {        //do stuff with the data you got back.    });});

Viewing all articles
Browse latest Browse all 15

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>