I'm making the upload of a single image in ajax. The problem is that the variable that should be saved the file is always undefined.
Here is the html code:
<form enctype="multipart/form-data" name='file'>
<input type="file" name="file" id="foto-hidden" multiple style="float:left"/>
<div class="pubblica"> Pubblica </div>
</form>
Here's the Ajax code:
$(document).on("click",'.pubblica', function()
{
var image = new FormData('file');
jQuery.each($('#foto-hidden')[0].files, function(i, file)
{
image.append('file-' + i, file);
});
if($("#option-select").val() != undefined)
{
id_squadra = $("#option-select").val();
}
$.ajax(
{
type: "POST",
url: "",
processData: false,
contentType: false,
data: { file: image, id_user: localStorage.getItem('id_user'), mobile: 1 }
});
//window.location = "index.html";
});
Who could help me? I do not understand why it behaves this way.
Aucun commentaire:
Enregistrer un commentaire