I want to make a js function that refreshes the CSRF token (that i stored in a div) and return the new value after it has been refreshed.
The problem is that i can not define the new token to my returning variable.
In this post i found out how to wait until the .load() function has finished. But how can i return the new token/value?
This is what i try to do.
function getCsrfToken() {
var csrfToken = null;
$("#csrf-token").load(location.href + " #csrf-token", function () {
csrfToken = $("#csrf-token").text();
});
// csrfToken is undefined here
return csrfToken;
}