Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

远程验证GET方式无效 #45

Closed
shelltea opened this issue Sep 25, 2013 · 1 comment
Closed

远程验证GET方式无效 #45

shelltea opened this issue Sep 25, 2013 · 1 comment
Assignees
Labels
Milestone

Comments

@shelltea
Copy link

从0.2.1升级到0.4.0后,之前正常的remote规则失效,使用默认的POST方式能正常验证,替换成GET方式不会触发任何验证。

js代码如下:

fields : {
    'email' : 'required;email;remote(GET:/api/accounts/checking/email)'
},

html代码如下:

<input id="email" name="email" type="text" class="form-control" autofocus="autofocus">

通过启用调试模式,在控制台输出:

0: api -> true
@ghost ghost assigned niceue Sep 25, 2013
@niceue
Copy link
Owner

niceue commented Sep 25, 2013

@shelltea
确实存在这个问题。
在问题修正之前,如果要使用GET方式,可以先自定义临时的remote规则。
代码参考:

$('#form').validator({
    rules: {
        remote: function(element){
            return $.ajax({
                url: 'check/email.php',
                type: 'get',
                data: element.name +'='+ element.value,
                dataType: 'json'
            });
        }
    },
    fields: {
        'email': 'required; email; remote;'
    },
    valid: function(form){
        $.ajax({
            url: 'results.php',
            type: 'post',
            data: $(form).serialize(),
            dataType: 'json',
            success: function(d){
                alert('提交成功!');
            }
        });
    }
});

@niceue niceue closed this as completed in 51a1dae Sep 25, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants