jquery validation with ajax call

前端 未结 4 1288
闹比i
闹比i 2020-12-06 00:58

I am using the jquery validation and i need to validate an email.

I use

    $(\"#myForm\").validate({
        rules: 
            email: {
                   


        
4条回答
  •  孤街浪徒
    2020-12-06 01:06

    first of all i want to tell you that if you are using post method in ajax then dont pass email in url.

     $.ajax({
            type: "POST",
            url: URLROOT + '/register/check/';
            data: {email:email};
             success: function (result) {
                if (result == 'exist') {
                  return false;
                 } else {
                 return true;
                 }
              }
          });`
    

    after that you remove parameter from controller's function.

    `public function check(l) {
      if($this->userModel->findUserByEmail($_POST['email'])==true)) {
       return 'exist';
      }
      return 'false';
     }`
    

    Try with this.

提交回复
热议问题