0

I would like to send my form to the server through jQuery's Ajax method. I have text boxes, text areas, select boxes, checkboxes, radio buttons and most importantly, files in my form.

What I was using for a form that did not have files in it is this:

$('form').serialize();

However now if I have a file field in my form I can't seem to do it. What the best practice (common practice) to send over a big list of form elements including files to the backend server with jQuery - without having to add each element manually to the FormData()?

Radical_Activity
  • 2,618
  • 10
  • 38
  • 70
  • Files are binary data, and although they *can* be serialised to strings, ie. Base64, it's not the ideal way of sending the file in an AJAX request. For that use a `FormData` object – Rory McCrossan Feb 15 '18 at 14:14
  • 1
    Also note that you don't have to add each element manually to the `FormData` object. You can use the constructor by passing the form reference as an argument to it, eg `var fd = new FormData(yourForm);` – Rory McCrossan Feb 15 '18 at 14:15

0 Answers0