• When Input file type not serialize in jquery

    $('.submit_add').click(function(e){ 
              e.preventDefault();
              var data = $('#myform').serialize();
    
              console.log(data); return false;
              $.ajax({ 
                  url: '/ajax',
                  type: 'POST',
                  cache: false, 
                  data: data,
                  dataType: 'json',
                  success: function(data) {
                              if (data.success == true ) {
                                window.location.href  = '/';
                              } else {
                                alert('Error : There is something wrong.');
                              }
                            },
                  error: function(jqXHR, textStatus, err){
                       alert('text status '+textStatus+', err '+err);
                   }
              })
          }); 
    
    
    Replace the above code by
    $('.submit_add').click(function(e){ 
              e.preventDefault();
              var data = new FormData($("#myform")[0]);
    
    
              console.log(data); return false;
              $.ajax({ 
                  url: '/ajax',
                  type: 'POST',
                  cache: false, 
                  data: data,processData: false,contentType: false,
                  dataType: 'json',
                  success: function(data) {
                              if (data.success == true ) {
                                window.location.href  = '/';
                              } else {
                                alert('Error : There is something wrong.');
                              }
                            },
                  error: function(jqXHR, textStatus, err){
                       alert('text status '+textStatus+', err '+err);
                   }
              })
          }); 
  • 0 comments:

    Post a Comment

    FAVOURITE LINE

    To steal ideas from one is plagiarism. To steal from many is Research.

    ADDRESS

    Mumbai , Maharashtra

    EMAIL

    shikha.pathak6@gmail.com
    shikha.the.swt.pari@gmail.com

    Skype

    shikha_pari