doushu2699 2015-07-08 12:41
浏览 31

使用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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 is not in the mmseg::model registry。报错,模型注册表找不到自定义模块。
    • ¥15 安装quartus II18.1时弹出此error,怎么解决?
    • ¥15 keil官网下载psn序列号在哪
    • ¥15 想用adb命令做一个通话软件,播放录音
    • ¥30 Pytorch深度学习服务器跑不通问题解决?
    • ¥15 部分客户订单定位有误的问题
    • ¥15 如何在maya程序中利用python编写领子和褶裥的模型的方法
    • ¥15 Bug traq 数据包 大概什么价
    • ¥15 在anaconda上pytorch和paddle paddle下载报错
    • ¥25 自动填写QQ腾讯文档收集表