django 使用jquery ajax post数据问题

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

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


<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>

 

 

 
posted @ 2015-10-15 11:20  普拉多VX  阅读(833)  评论(0编辑  收藏  举报