码迷,mamicode.com
首页 > 其他好文 > 详细

csrf

时间:2017-04-13 22:51:32      阅读:268      评论:0      收藏:0      [点我收藏+]

标签:htm   utf-8   ext   roo   type   mit   数据   get   pos   

html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <form action="/login/" method="POST">
        {% csrf_token %}
        <input type="text" name="user" />
        <input type="text" name="pwd" />
        <input type="checkbox" name="rmb" value="1" /> 10秒免登录
        <input type="submit" value="提交" />
        <input id="btn1" type="button" value="按钮" />
        <input id="btn2" type="button" value="按钮" />
    </form>

    <script src="/static/jquery-1.12.4.js"></script>
    <script src="/static/jquery.cookie.js"></script>
    <script>
        $(function(){
            $.ajaxSetup({
                beforeSend: function(xhr,settings){
                    xhr.setRequestHeader(X-CSRFtoken, $.cookie(csrftoken));
                }
            });

            $(#btn1).click(function () {
                $.ajax({
                    url: /login/,
                    type:"GET",
                    data: {user: root, pwd: 123},
                    // headers: {‘X-CSRFtoken‘: $.cookie(‘csrftoken‘)},
                    success:function(arg){

                    }
                })
            });
        })
    </script>
</body>
</html>
  • 通过form表单提交数据

    {% csrf_token%}

  • ajax提交数据

csrf

标签:htm   utf-8   ext   roo   type   mit   数据   get   pos   

原文地址:http://www.cnblogs.com/hongpeng0209/p/6706654.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!