var csrf_token = "IjZjMjI0MDRmY2JjY2MyMjgwZjUzMzY3NjQyOGQ5NWRkNjMxYzVjYjAi.GhKh9Q.M-UPEvwJ6bRiZ-eGd7nJzZgy4Uo"; $.ajaxSetup({ beforeSend: function(xhr, settings) { if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) { xhr.setRequestHeader("X-CSRFToken", csrf_token); } } });