/csrftoken设置,否则无法调用$.post/ function setupAjax() { $.ajaxSetup({ beforeSend: function (xhr, settings) { var csrftoken = $.cookie('csrftoken'); xhr.setRequestHeader("X-CSRFToken", csrftoken); } }); }
使用方法: $(function(){ setupAjax(); $.post(...); });