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

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -