mercredi 1 décembre 2021

csrf-token mismatch error in laravel on server

I'm using this code to submit data through ajax in laravel

$('#submit').submit(function (e) {
    e.preventDefault();

    let formData = new FormData(this);

    $.ajaxSetup({
        headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });
    $.ajax({
        xhr: function() {
          var xhr = new window.XMLHttpRequest();
      
          xhr.upload.addEventListener("progress", function(evt) {
            if (evt.lengthComputable) {
              var percentComplete = evt.loaded / evt.total;
              percentComplete = parseInt(percentComplete * 100);
             
      
              if (percentComplete === 100) {
               
              }
      
            }
          }, false);
      
          return xhr;
        },
        url: $(this).attr('action'),
        type: "POST",
        data:  formData,
        dataType:'JSON',
        contentType:false,
        cache: false,
        processData: false,

but getting csrf token mismatch when i upload my code on live server.

enter image description here

enter image description here

Any solution is highly appreciated Thanks



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire