0
Я хочу, чтобы отправить форму с помощью AJAX, но форма содержит входной файл есть моя форма:Отправить форму с вводом файла с помощью Ajax
<form name="form" id="form" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="libelle" >Libellé :</label>
<input type="text" name="libelle" class="form-control" id="libelle">
</div>
<div class="form-group">
<label for="libelle" >Photo :</label>
<input type="file" name="photo" class="form-control" id="photo">
</div>
<div class="form-group">
<label for="description">Déscription :</label>
<input type="text" name="description" class="form-control" id="description">
</div>
<div class="form-group">
<label for="libelle" >Prix Unitaire :</label>
<input type="text" name="prix_unitaire" class="form-control" id="prix_unitaire">
</div>
<div class="form-group">
<label for="sel1">Catégorie :</label>
<select class="form-control" id="categorie_id" name="categorie_id">
<option value="1">1</option>
</select>
</div>
<input type="hidden" name="produit_id" class="form-control" id="produit_id">
</form>
я читал, что я должен использовать: var data = new FormData(jQuery('form')[1]);
как можно я посылаю все формы с другим вводом в серию? Мой JQuery код:
return $.ajax({
type: "GET",
url: "/admin/addProduit",
cache: false,
data: $('form').serialize() ,
success: function(data) {
console.log(data);
},
error: function(response) {
console.log('error');
}
});
Вы пробовали это? –
Дайте мне знать, если вам нужна помощь в реализации этого. –