0

我正在使用淘汰赛验证插件,但我没有得到如何验证验证是真还是假

ko.validation.rules['remote'] = {
        async: true,
        validator: function ( val, parms, callback ) { 
            var defaults = {
                url: '/ajax/auth',
                type: 'POST',
                success: callback
            };

            var options = $.extend( defaults, parms );

            $.ajax( options );
        },
        message: 'Default Invalid Message'
    };

var username = ko.observable().extend({ remote : { data: {email : username} }});

// setting it will trigger validation
username.isValidating.subscribe(function(isValid){
     if(isValid){
         // save the username or whatever you do
     }else{
         // invalid 
     }


// ajax.php

function isValidEmail(){
        $data = $this->input->get_post();
        return is_valid_email($data['email']);
};

我总是变得无效请解释这是如何工作的

4

1 回答 1

1

callback您应该在 ajax-response 上调用 giventruefalse指示验证成功。

    validator: function ( val, parms, callback ) { 
        var defaults = {
            url: '/ajax/auth',
            type: 'POST',
            success: callback
        };

        var options = $.extend( defaults, parms );

        $.ajax(options, function(data){
            // data format depends on your implementation
            // just for example:
            if (data.result == 'ok') {
                callback(true);
            } else {
                callback(false);
            }
        });
    },
于 2013-03-01T12:49:27.743 回答