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.