this question has answer here:
- jquery ajax file upload php 4 answers
i did uploading files via ajax. can't file data. shows file data empty.
here ajax part.
$("#personal_image").on('click',function(event) { event.preventdefault(); var datastring = $("#personal_image").serialize(); console.log(datastring); $.ajax({ type: "post", url: location.origin+"/user/parsonal_image_submit/", secureuri :false, fileelementid :'user_image', data: datastring, datatype: "json", success: function(data) { //success }, error: function() { //error } }); })
check below code. hope work you. please use on form submit rather using on click.
$('#your_form_id').on('submit',function(e){ e.preventdefault(); var formdata = new formdata($(this)[0]); var url = $('#personal_image').attr('action'); $.ajax({ url: url, type: 'post', data: formdata, datatype: 'json', processdata: false, contenttype: false, //async: false, success: function(data){ //success } }); });
Comments
Post a Comment