php - jquery change event to submit form using ajax -
here form
<form name="uploadimg" id="uploadimg" class="profile-image" enctype="multipart/form-data"> <input type="file" name="profile" id="updprofileimg"> </form>
here jquery event
$("#updprofileimg:file").change(function() { $('#uploadimg').submit(function() { var querystring = new formdata($('form')[0]); $.ajax({ type: "post", url: 'index.php?route=account/edit/upload', data: querystring, contenttype: false, processdata: false, beforesend: function() { }, success: function() { } }) }) })
but change event not triggering form submit tried trigger('submit')
page refreshing instead of submitting in ajax.
you binding events incorrectly. have it, changing field trigger binding of submit. need this:
// bind submit event $('#uploadimg').submit(function() { var querystring = new formdata($('form')[0]); $.ajax({ type: "post", url: 'index.php?route=account/edit/upload', data: querystring, contenttype: false, processdata: false, beforesend: function() { }, success: function() { } }); }); // bind change event trigger submit $("#updprofileimg:file").change(function() { $("#uploadimg").submit(); });
Comments
Post a Comment