Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version
  1. Create a FormData object var formData = new FormData();
  2. Add files to the FormData object using the append() method formData.append('file', file);
  3. Set the processData and contentType options to false processData: false, contentType: false
  4. Set the type option to 'POST' type: 'POST'
  5. Set the url option to the endpoint where the file will be uploaded to url: '/upload'
  6. Set the data option to the FormData object data: formData
  7. Use the success() and error() functions to handle the response from the server success: function(response) { console.log('Success:', response); }, error: function(error) { console.log('Error:', error); }
  8. Make the AJAX request using the jQuery AJAX method $.ajax({ type: 'POST', url: '/upload', data: formData, processData: false, contentType: false, success: function(response) { console.log('Success:', response); }, error: function(error) { console.log('Error:', error); } });