Ajax submit phone number go to database validation and return status value instance in detail

Source: Internet
Author: User
This article is mainly for everyone to introduce the AJAX submitted mobile phone number to database verification and return the status of the relevant data, with a certain reference value, interested in small partners can refer to, hope to help everyone.


<script type= "Text/javascript" > $ (Function () {$ ('. Agree_regi '). Click (function () {  var phone = $.trim ($ ("#") Phone "). Val ());  if (phone = = "") {  Newalert (2, "Please enter phone number", null);  return false;  } else{   var reg =/^0?1[3|4|5|8| 7][0-9]\d{8}$/;   if (!reg.test (phone)) {    Newalert (2, "Please enter a valid mobile number", null);     return false;    }  }  var data ={  Phone:phone,  };    $.ajax ({  type: "POST",  URL: "{: U (' Register/phonefind ')}",  Data:data,  success:function (msg) {   if (msg== ' 0 ') {   Newalert (2, "phone number is wrong", null);   }   if (msg== ' 1 ') {   Newalert (2, "the mobile number is already registered, please login directly", null);   }   if (msg== ' 2 ') {   location.href= "/register/regowner?phone=" +phone;   }   if (msg== ' 3 ') {   location.href= "/register/regnest?phone=" +phone;}});}  ); });</script>

The backend receives the Ajax commit value, goes to the database query, and returns.


public function Phonefind () {if (!empty (I (' Param.phone '))) {//i method gets the value of the post commit $phone = I (' param   . Phone ');   $user = M ("Cuser"); $res = $user->where (Array (' phone ' = $phone))->find (); Go to the database query one, and return the IF (!empty ($res [' password ')) {$status =1;//password exists, the user directly login}elseif (!empty ($res)) {$status =2;//exists,         No password, set password, is the owner of}else{$status =3;//does not exist, is a visitor, registration}}else{$status =0;//mobile phone number is wrong} $this->ajaxreturn ($status); Returns the status value to the foreground} 
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.