使用codeigniter的Jquery验证远程方法

As you can imagine I want to use remote method to avoid username and email recurrences. In the documentation, they use a php file which does the same thing a controller in mvc pattern.

Here is my problem; do I have to create another php page to do that(can't I do that with my existing controller) Either way, I get a 404 - Not found or 500 - Internal server error.

$( "#myform" ).validate({
    rules: {
       email: {
           required: true,
           email: true,
           remote: "check-email.php" --> this file is what I mentioned about
       }
    }
});

and this is how I'm trying to do

uName:{
        required: true,
        minlength: 6,
        maxlength: 16,
        remote: {
           url: "user/validate", ---> controller/method
           type: "post"
        }
     },

I tried to create a php file, get the username and post it to controller manually, but I got a 404 - Not found error again.

EDIT 1

Using "http://example.com/controller/method" or "method" for the url is reaching the same method. I don't get 404 error when I use them but I got 505 error.

controller

public function validate(){
    $uName = $this->input->post('uName');
    $isUNameCount = $this->user_model->isVarExists($uName);
    if($isUNameCount > 0){
        return json_encode(false);
    }
}

model

public function isVarExists($var){
    $query = $this->db
        ->select($var)
        ->where('user_name', $var)
        ->get('user')
        ->num_rows();
    return $query;
}

Please tell me if I do it wrong.

SOLVED

As always, the problem was somewhere else. The select in the query was getting wrong column name and the method validate in the controller needed to echo something instead of returning it.