繁体   English   中英

带有codeigniter的jQuery验证插件远程功能

[英]jquery validation plug-in remote function with codeigniter

我正在使用jquery验证插件。 我不知道远程功能如何工作。

到目前为止,这是我的代码:

functions.js

user: {
            required: true,
            remote: {
                url: "http://localhost/iTransaction/home/checkUser",
                type: "post",
                async: false
            }
        }

控制器:

    function checkUser(){
    return $this->itransaction_model->checkUser();
}

模型:

function checkUser(){
    $this->db->select("user");
    $query = $this->db->get("member");
    $row = $query->row();
    echo $row->user;

    if($row->user == $this->input->post("user")){
        return true;
    }else{
        return false;
    }
}

遥控器应该检查用户名是否已经存在。

文档

通过jQuery.ajax(XMLHttpRequest)调用服务器端资源,并获取对应于已验证元素的名称及其值作为GET参数的键/值对。 使用默认消息,响应被评估为JSON,对于有效元素必须为true,对于无效元素可以为false,undefined或null。 或字符串,例如 该名称已被使用,改为尝试peter123 ”显示为错误消息。

您的控制器方法以对库没有任何意义的方式返回布尔值,并被解释为false。 您需要以其他方式返回验证结果:

function checkUser(){
    $this->output->set_content_type('application/json');
    $this->output->set_header('Cache-Control: no-cache, must-revalidate');
    $this->output->set_header('Expires: '.date('r', time()+(86400*365)));

    $output = json_encode(
        $this->itransaction_model->checkUser() ? true : 'That username is alreay in use'
    );

    $this->output->set_output($output);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM