本文實(shí)例為大家分享了ajax提交手機(jī)號(hào)去數(shù)據(jù)庫(kù)的具體代碼,并返回狀態(tài)值,供大家參考,具體內(nèi)容如下
<script type="text/javascript"> $(function(){ $('.agree_regi').click(function(){ var phone = $.trim($("#phone").val()); if(phone == ""){ NewAlert(2,"請(qǐng)輸入手機(jī)號(hào)",null); return false; }else{ var reg = /^0?1[3|4|5|8|7][0-9]/d{8}$/; if (!reg.test(phone)) { NewAlert(2,"請(qǐng)輸入有效的手機(jī)號(hào)碼",null); return false; } } var data ={ phone:phone, }; $.ajax({ type:"POST", url:"{:U('Register/PhoneFind')}", data:data, success:function(msg){ if(msg=='0'){ NewAlert(2,"手機(jī)號(hào)有誤",null); } if(msg=='1'){ NewAlert(2,"該手機(jī)號(hào)已經(jīng)注冊(cè),請(qǐng)直接登錄",null); } if(msg=='2'){ location.href="/Register/Regowner?phone="+phone; } if(msg=='3'){ location.href="/Register/Regnest?phone="+phone; } } }); }); });</script>
后臺(tái)接收ajax的提交值,去數(shù)據(jù)庫(kù)查詢,并返回。
public function PhoneFind(){ if(!empty(I('param.phone'))){ //I方法獲取post提交的值 $phone = I('param.phone'); $user = M("cuser"); $res=$user->where(array('phone' =>$phone))->find(); //去數(shù)據(jù)庫(kù)查詢一條,并以數(shù)組返回 if (!empty($res['password'])) { $status=1;//密碼存在,用戶直接登錄 }elseif(!empty($res)){ $status=2;//存在,沒有密碼,設(shè)置密碼,是業(yè)主 }else{ $status=3;//不存在,是游客,注冊(cè) } }else{ $status=0;//手機(jī)號(hào)有誤 } $this->ajaxReturn($status); //返回狀態(tài)值給前臺(tái) }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持錯(cuò)新站長(zhǎng)站。
新聞熱點(diǎn)
疑難解答
圖片精選