vendredi 7 février 2020

How to update the header information during ajax replay [duplicate]

I am using ajax replay and during ajax call I want to update the X-CSRF-TOKEN value but I am not able to change the X-CSRF-TOKEN sending old value.

$.ajax({
         url: url,
         type: requestType,
         contentType: contentType,
         data: data,
         beforeSend: function(jqXHR, settings) {
             if (typeof beforeSendCallbackFunction === "function") {                
                 beforeSendCallbackFunction();
             }
         },
         success: function(response, textStatus, jqXHR) {
            if(typeof JSON.parse(response) =='object'){
                var value = JSON.parse(response);
                if('_token' in value) {
                if(value._token != 'logout') {                    
                    $.ajaxSetup({
                        headers: {
                            "X-CSRF-TOKEN": value._token
                        },
                        async: false
                     });
                   $.ajax(this);
                   }
               }
            }
        }
    });


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/38aq8QO
via IFTTT

Aucun commentaire:

Enregistrer un commentaire