mirror of
https://github.com/billz/raspap-webgui.git
synced 2023-10-10 13:37:24 +02:00
improve global ajax event handling
This commit is contained in:
parent
da69d3d768
commit
752e8ccf66
21
js/custom.js
21
js/custom.js
@ -160,7 +160,14 @@ function setupBtns() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateCSRFToken(xhr, settings) {
|
function setCSRFTokenHeader(event, xhr, settings) {
|
||||||
|
var csrfToken = $('meta[name=csrf_token]').attr('content');
|
||||||
|
if (/^(POST|PATCH|PUT|DELETE)$/i.test(settings.type)) {
|
||||||
|
xhr.setRequestHeader("X-CSRF-Token", csrfToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateCSRFTokens(event, xhr, settings) {
|
||||||
var newToken = xhr.getResponseHeader("X-CSRF-Token");
|
var newToken = xhr.getResponseHeader("X-CSRF-Token");
|
||||||
if (newToken) {
|
if (newToken) {
|
||||||
$('meta[name=csrf_token]').attr('content', newToken);
|
$('meta[name=csrf_token]').attr('content', newToken);
|
||||||
@ -168,15 +175,9 @@ function updateCSRFToken(xhr, settings) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$.ajaxSetup({
|
$(document)
|
||||||
beforeSend: function(xhr, settings) {
|
.ajaxSend(setCSRFTokenHeader)
|
||||||
var csrfToken = $('meta[name=csrf_token]').attr('content');
|
.ajaxComplete(updateCSRFTokens);
|
||||||
if (/^(POST|PATCH|PUT|DELETE)$/i.test(settings.type)) {
|
|
||||||
xhr.setRequestHeader("X-CSRF-Token", csrfToken);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
ajaxComplete: updateCSRFToken
|
|
||||||
});
|
|
||||||
|
|
||||||
$().ready(function(){
|
$().ready(function(){
|
||||||
pageCurrent = window.location.href.split("?")[1].split("=")[1];
|
pageCurrent = window.location.href.split("?")[1].split("=")[1];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user