尝试使用Dj-rest-auth包设置密码重置过程时。我遇到了一个问题,让提交按钮来完成对rest_password_reset_confirm api端点的post请求。我一直收到与'ContentType‘相关的错误信息,$.post方法只执行GET请求。我从dj-rest-auth here中的演示应用程序中获取了表单和所有内容。
发布于 2021-05-30 18:17:55
我必须用base.html重写下面的ajax脚本才能正常工作。我还为success和failure response添加了两个新div。
<div class="form-group api-response-success" style="color: green;"></div>
<div class="form-group api-response-error" style="color: red;"></div>
$().ready(function(){
$('form.ajax-post button[type=submit]').click(function(e){
var form = $('form.ajax-post');
var url = form.attr('action');
data = form.serializeArray();
var object_with_key_value = {};
$.map(data, function(n, i){
object_with_key_value[n['name']] = n['value'];
});
$.ajax({
'url': url,
'type':"POST",
'data': JSON.stringify(object_with_key_value),
'contentType': 'application/json',
'success': function(data){
$('.api-response-success').html("Password has been reset with the new password.");
},
'error': function(data){
$('.api-response-error').html("Something went wrong, please try again.");
},
});
e.preventDefault();
})
});
https://stackoverflow.com/questions/67760038
复制相似问题