<script type="text/javascript">
    function csrfSafeMethod(method) {

        // These HTTP methods do not require CSRF protection
        return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));

    }

    $.ajaxSetup({
        beforeSend: function(xhr, settings) {

            if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
                xhr.setRequestHeader('X-CSRFToken', '{{ csrf_token }}');
            }

        }
    });
</script>
