FIX: Memory leak when adding ajax prefilter repeatedly.
This commit is contained in:
parent
c322cccd53
commit
47095a7fa1
|
@ -1,16 +1,21 @@
|
||||||
// Append our CSRF token to AJAX requests when necessary.
|
// Append our CSRF token to AJAX requests when necessary.
|
||||||
|
|
||||||
|
let installedFilter = false;
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "csrf-token",
|
name: "csrf-token",
|
||||||
initialize: function(container) {
|
initialize: function(container) {
|
||||||
var session = container.lookup("session:main");
|
|
||||||
|
|
||||||
// Add a CSRF token to all AJAX requests
|
// Add a CSRF token to all AJAX requests
|
||||||
|
let session = container.lookup("session:main");
|
||||||
session.set("csrfToken", $("meta[name=csrf-token]").attr("content"));
|
session.set("csrfToken", $("meta[name=csrf-token]").attr("content"));
|
||||||
|
|
||||||
|
if (!installedFilter) {
|
||||||
$.ajaxPrefilter(function(options, originalOptions, xhr) {
|
$.ajaxPrefilter(function(options, originalOptions, xhr) {
|
||||||
if (!options.crossDomain) {
|
if (!options.crossDomain) {
|
||||||
xhr.setRequestHeader("X-CSRF-Token", session.get("csrfToken"));
|
xhr.setRequestHeader("X-CSRF-Token", session.get("csrfToken"));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
installedFilter = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue