FIX: Memory leak when adding ajax prefilter repeatedly.

This commit is contained in:
Robin Ward 2019-06-11 11:50:11 -04:00
parent c322cccd53
commit 47095a7fa1
1 changed files with 12 additions and 7 deletions

View File

@ -1,16 +1,21 @@
// Append our CSRF token to AJAX requests when necessary.
let installedFilter = false;
export default {
name: "csrf-token",
initialize: function(container) {
var session = container.lookup("session:main");
// Add a CSRF token to all AJAX requests
let session = container.lookup("session:main");
session.set("csrfToken", $("meta[name=csrf-token]").attr("content"));
$.ajaxPrefilter(function(options, originalOptions, xhr) {
if (!options.crossDomain) {
xhr.setRequestHeader("X-CSRF-Token", session.get("csrfToken"));
}
});
if (!installedFilter) {
$.ajaxPrefilter(function(options, originalOptions, xhr) {
if (!options.crossDomain) {
xhr.setRequestHeader("X-CSRF-Token", session.get("csrfToken"));
}
});
installedFilter = true;
}
}
};