Php value transfer method and ajax verification function, php transfer ajax Verification
Three methods for PHP foreground value passing to the background for verification
1. post, get, and ajax
The post and get methods are defined by the method on the form. The main reason is that ajax dynamically transmits values for background verification.
2. the ajax dynamic value passing code is as follows:
// Set a function u_ajax (uname, upass) {// Create ajax if (window. XMLHttpRequest) {xmlhttp = new XMLHttpRequest ();} else {xmlhttp = new ActiveObject ("Microsoft. XMLHTTP ");} // open a page xmlhttp. open ("post ",".. /dao/loginAction. php ", true); // this sentence should be added when the post method is used to pass the value, otherwise the background will not receive xmlhttp. setRequestHeader ("Content-type", "application/x-www-form-urlencoded"); // The value is passed to xmlhttp. send ("uname =" + uname + "&" + "upassword =" + upass ); // Prepare to return and process xmlhttp. onreadystatechange = function () {if (xmlhttp. readyState = 4 & xmlhttp. status = 200) {// The returned value is var res = xmlhttp. responseText; // Response Processing if (res = "errn") {document. getElementById ("err "). style. visibility = "visible"; document. getElementById ("err "). style. color = "red"; document. getElementById ("err "). innerHTML = "incorrect account or password! "; Return false;} else {// if no value is returned, it is set to null document. getElementById (" err "). innerHTML =" ";}}}// ajax
/Note: After ajax is returned, whether it is returned or not, the final function returns underfined/. In this case, you can use the following method to verify the passed value. You can first judge, if the returned tag is an error code, write the value into a hidden tag and use textContent to read whether the specified value is written to the tag to check whether the entered value is correct;
Return true if it is correct, and false if it is incorrect;
Since ajax does not return any value, it is underfined, so we need to use another independent function to call the ajax function.
// Call the above function and use the value generated above to judge function lg_verity () {// call the above function, and return here, in the ajax section, my_lg_verity () is not used; // you can obtain the content value var errText = document. getElementById ("err "). textContent; // used to determine whether a write value exists and whether the if (errText. length> 0) {return false ;}}
The above is a small series of php value passing method and ajax verification functions, I hope to help you, if you have any questions, please leave a message, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!