Ask Your Question
3

What is the process for uploading files using the stream type in the body parameter of Jquery ajax?

asked 2022-06-20 11:00:00 +0000

ladyg gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-10-28 12:00:00 +0000

woof gravatar image
  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); } });
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-06-20 11:00:00 +0000

Seen: 12 times

Last updated: Oct 28 '22