I am trying to upload image after form submit using ajax call, having an issue that annoying me, the new FormData($(this)[0])
gives me actual values, but whenever I try to send it through ajax its malfunctioning and reloads the page, so I cant see the console as well, please correct me where I am wrong.
My javascript code
$("#editImage").submit(function(){
var data = new FormData($(this)[0]);
console.log(data);
return false;
$.post("../galImages", data).done(function(response){
console.log(response);
});
return false;});
My HTML code
<form name="edit-image" id="editImage" action="" method="post" enctype="multipart/form-data"><input type="file" name="change-image" accept="image/*" class="form-control mb-20" value="Upload Image">
<input type="hidden" name="edit-img-id" id="editImageId"><input type="submit" class="btn btn-primary" value="Save Changes" id="submitEditImgForm"></form>
however file datas are posted in the PHP page, and one more thing how can I send hidden field value along with formdata object. I am a noobie in ajax $.post
method. Please help me if anyone have any idea.