javascript - Why the change in input type=file is not identified with `form.serialzie()` -
i checking whether values in form has been changed before submitting updation. other controls inside form, if changed, identified not input type=file control. below sample trying , if try submitting form or without uploading file, response not changed. why behavior input type=file? why change in input type=file not identified? 
var form_serialize = "";  $(function() {    form_serialize = $("#frmprofile").serialize();  })    $('.submit').on('click', function(e) {    e.preventdefault();    var ischanged = $("#frmprofile").serialize() == form_serialize ? false : true;    if (ischanged)      $('body').append('changed');    else      $('body').append('not changed');  })  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <form id="frmprofile">    <input type="file" />    <input type="submit" class="submit" value="submit" />  </form>  
as per documentation of serialize()
data file select elements not serialized.
instead can use jquery ajaxform plugin support.
or can use formdata object , refer these questions : jquery/ajax form submission (enctype="multipart/form-data" ). why 'contenttype:false' cause undefined index in php? , sending multipart/formdata jquery.ajax
Comments
Post a Comment