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?