1
I am creating the product registration form of a website, and in it, all forms are submitted by ajax to an api. The problem is that in this particular form I need to send images to the server. I am trying to use the Formdata object to send, but without success. Follow the javascript code I am using:
$("#formProduto").submit((e) => {
var formProduto = document.getElementById('formProduto');
var formData = new FormData(formProduto);
$.ajax("/admin/produto/api", {
type: "POST",
data: formData,
success: (data) => {
//Sucesso
}
}
return e.preventDefault();
});
Using data: $("#formProduto").serialize()
(without the file, of course) ajax works normally, when I change the above code it just ignores the e.preventDefault();
and submit the form to the page itself.
Even using ajax to submit the form I need to set the enctype?
– Wesley Nascimento
Form information is not coming to the server-side (Nodejs/Express).
– Wesley Nascimento
Had done with PHP, with Node may be a different way. Without the enctype the file fields are not sent together with the other fields. Submit the form is see the fields being passed in the request, if using Chrome see in the Network tab.
– fernandoandrade
The module I am using does not support sending files, I will have to use another to get the information, change my entire backend Ahhhhh, mas vlw ai cara
– Wesley Nascimento
Blz, good luck with the refactoring.
– fernandoandrade