Urgent PHP + Ajax solves problems related to user login verification

Source: Internet
Author: User
Urgent !! How does PHP + Ajax solve the problem of user login verification? In the form, there are two attributes: user name and password. click the button to trigger the AJAX function. This AJAX function extracts the values of "user name" and "password" in the form and sends them to the background program for verification. php writes the background program, the php program verifies the "user name" and "password" respectively. If an error occurs in the user name, the code is sent back to ajax. & lt; div & Urgent! is displayed !! How does PHP + Ajax solve the problem of user login verification?
In the form, there are two attributes: user name and password. click the button to trigger the AJAX function. This AJAX function extracts the values of "user name" and "password" in the form and sends them to the background program for verification. php writes the background program, the php program verifies the "user name" and "password" respectively. If an error occurs in the user name, a prompt is sent back to ajax. the prompt is displayed. if the same password is incorrect, the prompt is displayed, now the username and password can be correctly transferred to the PHP program for correct verification, but xmlHttp. responseText, how can we achieve the above effect? Urgent !!!
------ Solution --------------------
Paste your code!

If you need to assign values to different targets with conditions in the callback function, you need to return the control information.
------ Solution --------------------
Index.html





Untitled Document

Script


User name:


Password







Ajax. js
Var http_request;
Function send_request (url, method ){
Http_request = false;
If (window. XMLHttpRequest ){
Http_request = new XMLHttpRequest ();
If (http_request.overrideMimeType ){
Http_request.overrideMimeType ('text/XML ');
}
}
Else if (window. ActiveXObject ){
Try {
Http_request = new ActiveXObject ("Msxml2.XMLHTTP ");
} Catch (e ){
Try {
Http_request = new ActiveXObject ("Microsoft. XMLHTTP ");
} Catch (e ){}
}
}
If (! Http_request ){
Window. alert ("the XMLHttpRequest object instance cannot be created .");
Return false;
}
Switch (method ){
Case 1: http_request.onreadystatechange = chk; break;
}
Http_request.open ("GET", url, true );
Http_request.send (null );
}

Function check (){
Send_request ("check. php? Action = "+ document. getElementById ('pw '). value, 1 );


Function chk (){
If (http_request.readyState = 4 ){
If (http_request.status = 200 ){
Document. getElementById ("user"). innerHTML = "";
Document. getElementById ("user"). value = http_request.responseText;
} Else {
Alert ("the page you requested is abnormal. ");
}
} Else {
Document. getElementById ("user"). innerHTML = "reading data ...... ";
}
}


Check. php


If (exists ){
Echo "correct ";
} Else {
Echo "incorrect ";
}
?>


------ Solution --------------------
Upload json
------ Solution --------------------
Name reserved! Isn't jquery better?

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.