It is relatively simple to implement the login function through ajax + php. this is a simple example, fixed characters, and Ajax can be read from the database in practical applications.
HTML section:
Function postRequest (strURL ){
Var xmlHttp;
If (window. XMLHttpRequest) {// For Mozilla, Safari ,...
Var xmlHttp = new XMLHttpRequest ();
}
Else if (window. ActiveXObject) {// For Internet Explorer
Var xmlHttp = new ActiveXObject ("Microsoft. XMLHTTP ");
}
XmlHttp. open ('post', strURL, true );
XmlHttp. setRequestHeader ('content-type', 'application/x-www-form-urlencoded ');
XmlHttp. onreadystatechange = function (){
If (xmlHttp. readyState = 4 ){
Updatepage (xmlHttp. responseText );
}
}
XmlHttp. send (strURL );
}
Function updatepage (str ){
If (str = "yes "){
Alert ("Welcome User ");
} Else {
Alert ("Invalid Login! Please try again! ");
}
}
Function call_login (){
Var username = parameter doc ument. f1.username. value;
Var password = parameter doc ument. f1.password. value;
Var url = "login. php? Username = "+ username +" & password = "+ password;
PostRequest (url );
}
PHP script login. php:
$ Username = $ _ GET ["username"];
$ Password = $ _ GET ["password"];
If ($ username = "admin" & $ password = "admin "){
Echo "yes ";
} Else {
Echo "No ";
}
?>