django 使用jquery ajax post数据问题

django 开启了CSRF功能致使jquery ajax post数据报错jquery

解决方法在post数据里引入csrfmiddlewaretoken: '{{ csrf_token }}'},同时须要在form表单中设置{% csrf_token %}ajax

 
<script src="/static/jquery/dist/jquery.min.js"></script>
                  <script>
                       $(function(){
                            $("#postset").click(function() {
                                $.post("", {newpasswd1: "John", newpasswd2: "John",csrfmiddlewaretoken: '{{ csrf_token }}'},function (data) {
                                            alert("Data Loaded: " + data);
                                        });
                            });
                        });
                  </script>
相关文章
相关标签/搜索