Simple example Ajax with PHP code implementation login effect Code _php tutorial

Source: Internet
Author: User
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 = Window.document.f1.username.value;
var password = window.document.f1.password.value;
var url = "Login.php?username=" + username + "&password=" +password;
Postrequest (URL);
}













PHP Script Section login.php:

$username =$_get["username"];
$password =$_get["Password"];
if ($username = = "Admin" && $password = = "Admin") {
echo "Yes";
}else{
echo "No";
}
?>

http://www.bkjia.com/PHPjc/319162.html www.bkjia.com true http://www.bkjia.com/PHPjc/319162.html techarticle HTML part: HTML head scrīptlanguage= "javascrīpt" Functionpostrequest (strurl) {varxmlhttp; XMLHttpRequest) {//formozilla,safari,... varxmlhttp=newxmlhttprequest ();} e ...

  • 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.