Jquery如何使用csrf

来源:互联网 发布:science online数据库 编辑:程序博客网 时间:2024/06/08 18:52
     var csrftoken = $.cookie('csrftoken');         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", csrftoken);                }            }        });

如上图代码,把token取出来,一同发送即可。