【发布时间】:2016-01-06 09:12:44
【问题描述】:
想做基于 ajax 的授权。 清单:
<script type="text/javascript">
$('#activeform').on('submit', function(event){
event.preventDefault();
var _self = $(this);
var token = $('input[name="csrfmiddlewaretoken"]').val();
$.ajax({
type: _self.attr('method'),
url: _self.attr('action'),
data: JSON.stringify({
"username": $('#id_username').val(),
"password1": $('#id_password1').val(),
"password2": $('#id_password2').val(),
"csrfmiddlewaretoken": token}),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(json) {
alert("Success")},
error: function( xhr, textStatus ) {
alert( [ xhr.status, textStatus ] )},
complete: function() {
alert("Msg sended")},
crossDomain: false
});
}); </script>
得到 403 错误和成功消息。如何解决这个问题?
【问题讨论】: