Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

shahr's avatar
Level 10

ajax to vue 3

I want to convert from jQuery to VUE 3 to upload files.

$.ajax({
    url: 'My url here',
    data: formData,
    type: 'POST',
    contentType: false, // NEEDED, DON'T OMIT THIS (requires jQuery 1.6+)
    processData: false, // NEEDED, DON'T OMIT THIS
    // ... Other options like success and etc
});
0 likes
1 reply
LaryAI's avatar
Level 58

Here's an example of how to use the fetch API in Vue 3 to upload files:

const formData = new FormData();
formData.append('file', file);

fetch('My url here', {
  method: 'POST',
  body: formData,
})
.then(response => {
  // Handle response
})
.catch(error => {
  // Handle error
});

Note that fetch does not require the contentType and processData options like $.ajax does. Also, make sure to replace file with the actual file you want to upload.

Please or to participate in this conversation.