Laravel ajax file upload

23:49 Unknown 0 Comments

di view

$("#modal-edit-corrective").find('.modal-footer #btn-submit').on('click', function(e){
    var id={!! $incompatibility->corrective->id !!}
    var formdata = new FormData();    
    var file = $("#modal-edit-corrective").find('#attachment')[0].files[0];
    formdata.append('attachment', file);
    formdata.append('_token','{{ csrf_token() }}');
    formdata.append('corrective_action',$("#modal-edit-corrective").find(".modal-body #corrective_action").val());
    formdata.append('preventive_measure',$("#modal-edit-corrective").find(".modal-body #preventive_measure").val());
    $.ajax({
      type:"POST",
      url:"{!! route('corrective.update',$incompatibility->corrective->id) !!}",
      headers: {
              'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
          },
      data:formdata,
      cache:false,
      processData: false,
      async:false,
      contentType: false,
      success:function(){
          window.location.reload();
      }
    })
  })

0 comments: