Php value transfer method and ajax verification function, php transfer ajax Verification

Source: Internet
Author: User

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!

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.