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>
相關文章
相關標籤/搜索