Ajax submits the mobile phone number to the database for verification and returns the status value and ajax status value.

Source: Internet
Author: User

Ajax submits the mobile phone number to the database for verification and returns the status value and ajax status value.

The examples in this article share the code for submitting a mobile phone number to the database through ajax and return the status value for your reference. The details are as follows:

<Script type = "text/javascript"> $ (function () {$ ('. agree_regi '). click (function () {var phone = $. trim ($ ("# phone "). val (); if (phone = "") {NewAlert (2, "Enter your mobile 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, "enter a valid phone 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, "Incorrect mobile phone number", null);} if (msg = '1') {NewAlert (2, "This mobile phone number has been registered, please log on 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 submission value, queries the database, and returns the result.

Public function PhoneFind () {if (! Empty (I ('Param. phone ') {// I method to obtain the value submitted by post $ phone = I ('Param. phone '); $ user = M ("cuser"); $ res = $ user-> where (array ('phone' => $ phone)-> find (); // query a record in the database and return if (! Empty ($ res ['Password']) {$ status = 1; // The password exists and the user logs in directly} elseif (! Empty ($ res) {$ status = 2; // There is no password, set the password, it is the owner} else {$ status = 3; // it does not exist, it is a tourist, registration} else {$ status = 0; // incorrect mobile phone number} $ this-> ajaxReturn ($ status); // return the status value to the front end}

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

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.