帮助我的远程方法的jquery验证插件 [英] Help me with remote method of jquery validation plugin

查看:112
本文介绍了帮助我的远程方法的jquery验证插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以帮助我使用jquery remote:验证方法。我的意思是我得到如何使用它在jquery部分。只有任何人都可以告诉我服务器端的一部分。我使用PHP和codeigniter做到这一点。请考虑以下示例:

  $(#myform)。validate({
rules:{
email:{
required:true,
email:true,
remote:validate / check
}
}
}

现在任何人都可以告诉我validate控制器中的check函数的代码是什么?

$关键是你应该使用 echo json_encode(TRUE / FALSE); 到将验证结果返回到jquery



控制器示例:

  --------------------------------- 
//电子邮件EXISTS(true或false)
// ---------------------------------
private function email_exists($ email)
{
$ this-> db-> where('email',$ email);
$ query = $ this-> db-> get('users');
if($ query-> num_rows()> 0){return TRUE; } else {return FALSE; }
}

// ---------------------------------
// AJAX请求,如果电子邮件存在
// ---------------------------------
function register_email_exists()
{
if(array_key_exists('email',$ _ POST)){
if($ this-> email_exists($ this-& > post('email'))== TRUE){
echo json_encode(FALSE);
} else {
echo json_encode(TRUE);
}
}
}

本教程将帮助您了解 http://www.joshuawinn .com / check-if-email-username-exists-with-codeigniter-and-jquery-validation /


Can anyone help me with jquery remote: validation method. I mean I got how to use it in the jquery part. Just can anyone tell me the server side part. I am using PHP and codeigniter to do it. Just consider an example below:

$("#myform").validate({ 
    rules: { 
        email: { 
            required: true, 
            email: true, 
            remote: "validate/check" 
        } 
    } 
});

So now can anyone tell me what's the code for check function in validate controller?

解决方案

The point is that, you should use echo json_encode(TRUE/FALSE); to return the validation result to jquery

Controller Example:

//---------------------------------
// EMAIL EXISTS (true or false)
//---------------------------------
private function email_exists($email)
{
  $this->db->where('email', $email);
  $query = $this->db->get('users');
  if( $query->num_rows() > 0 ){ return TRUE; } else { return FALSE; }
}

//---------------------------------
// AJAX REQUEST, IF EMAIL EXISTS
//---------------------------------
function register_email_exists()
{
  if (array_key_exists('email',$_POST)) {
    if ( $this->email_exists($this->input->post('email')) == TRUE ) {
      echo json_encode(FALSE);
    } else {
      echo json_encode(TRUE);
    }
  }
}

This tutorial would help you to understand http://www.joshuawinn.com/check-if-email-username-exists-with-codeigniter-and-jquery-validation/

这篇关于帮助我的远程方法的jquery验证插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆