jQuery验证远程选项烧瓶 [英] jQuery Validation Remote option Flask

查看:150
本文介绍了jQuery验证远程选项烧瓶的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是我的HTML:

$ b我试图检查表格,如果新用户的电子邮件地址已经存在。
$

  $(#createform)。validate({
errorClass:errormessage,
validClass:success,

规则:{
fname:{
required:true,
minlength:2,
string:true,
},

lname:{
required:true,
minlength:2,
string:true,
},

email:{
必填:true,
email:true,
remote:$ .getJSON($ SCRIPT_ROOT +/ _check_mail)
},

密码:
required:true,
minlength:5,
},

confirmpassword:{
equalTo :#password
}
}

这是我的Flask方法:

  @ app.route('/ _ check_mail')
def check_mail():
mail = request.args.get('email')
check = database.check_mail(mail)
return check

其中database.check_mail(邮件)检查电子邮件是否已经在数据库中,并返回True或False(以JSON格式)。



当我第一次加载页面,客户端试图访问flask URL(/ _check_mail)时,它可以正常工作:


  • 请求URL: http://0.0.0.0:5000/_check_mail

  • 请求方法:获取状态
  • 代码:200 OK



但是当我输入电子邮件时,请求到获得404响应的服务器:


  • 请求URL: http://0.0.0.0:5000 /[object%20Object]?email=arnoutaertgeerts%40gmail.com

  • 请求方法:GET

  • 状态码: 404未找到



所以我认为发送邮件时出现问题?任何想法?

解决方案

问题解决了!我用我的请求:

 电子邮件:{
required:true,
email:true,
remote:function(request,response){
$ .getJSON($ SCRIPT_ROOT +/ _check_mail,{
email:$('#email')。val()
},回答);

code


$ b现在除了显示错误信息之外,当电子邮件已经存在时,我返回带有错误信息的字符串(如文档中所述),但不显示消息。但是,当我看到这些消息时,我清楚地听到了它的意思!


I'm trying to check in a form if the email address of the new user enters already exists.

This is my HTML:

$("#createform").validate({
            errorClass: "errormessage",
            validClass: "success",

        rules: {
            fname: {
                required: true,
                minlength: 2,
                string: true,
            },

            lname: {
                required: true,
                minlength: 2,
                string: true,
            },

            email: {
                required: true,
                email: true,
                remote: $.getJSON($SCRIPT_ROOT + "/_check_mail")
            },

            password: {
                required: true,
                minlength: 5,
            },

            confirmpassword: {
                equalTo: "#password"
            }
        }

And this is my Flask method:

@app.route('/_check_mail')
def check_mail():
    mail = request.args.get('email')
    check = database.check_mail(mail)
    return check

where the database.check_mail(mail) checks if the email is already in the database and returns True or False (in JSON).

When I first load the page and the client tries to acces the flask URL (/_check_mail) it works:

  • Request URL:http://0.0.0.0:5000/_check_mail
  • Request Method:GET Status
  • Code:200 OK

But when I enter an email, i send this request to the server that gets a 404 respons:

  • Request URL:http://0.0.0.0:5000/[object%20Object]?email=arnoutaertgeerts%40gmail.com
  • Request Method:GET
  • Status Code:404 NOT FOUND

So I think there is a problem sending the email along? Any ideas?

解决方案

Problem solved! I used this for my request:

email: {
    required: true,
    email: true,
    remote: function( request, response ) {
        $.getJSON($SCRIPT_ROOT + "/_check_mail", {
        email: $('#email').val()
        }, response);
}

Now everything works except for displaying the error message. When the email already exists I return the string with the error message (as told in the documentation) but the messages doesn't get displayed. But I clearly recieve it when looking at the incomming responses!

这篇关于jQuery验证远程选项烧瓶的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆