Javascript 其中一个json.dumps值为null

Javascript 其中一个json.dumps值为null,javascript,json,django,django-authentication,parsley.js,Javascript,Json,Django,Django Authentication,Parsley.js,我正在使用Parsley.js和Django设置前端用户身份验证检查。 这是我的看法 @requires_csrf_token def password_check(request): email = request.POST.get('email') password = request.POST.get('password1') user = authenticate(email=email, password=password) if request.is

我正在使用Parsley.js和Django设置前端用户身份验证检查。 这是我的看法

@requires_csrf_token
def password_check(request):
    email = request.POST.get('email')
    password = request.POST.get('password1')
    user = authenticate(email=email, password=password)

    if request.is_ajax():
        if user and user.is_active:
            res = "These password and e-mail are ok."
            ajax_vars_login = {'response': res, 'email': email, 'password': password}
            json_data_login = json.dumps(ajax_vars_login)
        else:
            res = "The e-mail or the password field aren't correct."
            ajax_vars_login = {'response': res, 'email': email, 'password': password}
            json_data_login = json.dumps(ajax_vars_login)

        return HttpResponse(json_data_login, content_type='application/json')
这是欧芹验证器:

Parsley.addAsyncValidator(
  'emailPwCombination', function (xhr) {
       var password = $('#password').parsley();
       var email = $('#email').parsley();
       var response = xhr.responseText;
       var jsonResponse = JSON.parse(response);
       var jsonResponseText = jsonResponse["response"];

       if(jsonResponseText == 'These password and e-mail are ok.')
           return true;
       if(jsonResponseText == '404')
           return false;
  }, '/password_check/'
);
问题是,电子邮件似乎没有发送到服务器,因为每当我按submit时,都会收到两个xhr响应。
第一项答复:

{password: null, response: "The e-mail or the password field aren't correct.",…}
email: "example@gmail.com"
password: null
response: "The e-mail or the password field aren't correct."
{password: "examplepassword", response: "The e-mail or the password field aren't correct.", email: null}
email: null
password: "examplepassword"
response: "The e-mail or the password field aren't correct."
第二项答复:

{password: null, response: "The e-mail or the password field aren't correct.",…}
email: "example@gmail.com"
password: null
response: "The e-mail or the password field aren't correct."
{password: "examplepassword", response: "The e-mail or the password field aren't correct.", email: null}
email: null
password: "examplepassword"
response: "The e-mail or the password field aren't correct."

我缺少什么?

此代码在异步验证器中,因此每次调用值时,它都会将其发送到后端。因此,您将收到两个单独的请求,一个仅包含电子邮件,另一个仅包含密码


我想你还不明白欧芹是干什么用的。它用于根据一组标准验证单个字段;不用于将完整形式的数据发送到后端进行处理。这只需几行基本jQuery即可完成,这里根本不需要欧芹。

此代码位于异步验证器中,因此每次调用值时,它都会将其发送到后端。因此,您将收到两个单独的请求,一个仅包含电子邮件,另一个仅包含密码


我想你还不明白欧芹是干什么用的。它用于根据一组标准验证单个字段;不用于将完整形式的数据发送到后端进行处理。这只需几行基本jQuery即可完成,这里根本不需要欧芹。

是的,我认为它既可以用于单个字段的确认,也可以用于表单处理。谢谢您的回答:)是的,我想它要么用于单个字段的确认,要么用于表单处理。谢谢你的回答:)