php - Page reloads even after return false in ajax $.post request -
i trying upload image after form submit using ajax call, having issue annoying me, new formdata($(this)[0])
gives me actual values, whenever try send through ajax malfunctioning , reloads page, cant see console well, please correct me 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 posted in php page, , 1 more thing how can send hidden field value along formdata object. noobie in ajax $.post
method. please me if have idea.
as upload image (my mistake, forgot first!) : important parts ones needed upload
otherwise fail
$(function () { $('#my_form').on('submit', function (e) { e.preventdefault(); var $form = $(this); var formdata = (window.formdata) ? new formdata($form[0]) : null; var data = (formdata !== null) ? formdata : $form.serialize(); $.ajax({ url: $form.attr('action'), type: $form.attr('method'), contenttype: false, // needed upload processdata: false, // needed upload datatype: 'json', // return data: data, success: function (response) { // response } }); }); });
this code not mine, found it, adapted long time ago, can't credit original owner don't remember she/he :/
Comments
Post a Comment