A simple example of AJAX combined with PHP code to achieve login effect code

Source: Internet
Author: User
PHP script login. php: A simple example of AJAX combined with PHP code to achieve the login effect code

HTML section:
 

XML/HTML code
  1. Function postRequest (strURL ){
  2. Var xmlHttp;
  3. If (window. XMLHttpRequest) {// For Mozilla, Safari ,...
  4. Var xmlHttp = new XMLHttpRequest ();
  5. }
  6. Else if (window. ActiveXObject) {// For Internet Explorer
  7. Var xmlHttp = new ActiveXObject ("Microsoft. XMLHTTP ");
  8. }
  9. XmlHttp. open ('post', strURL, true );
  10. XmlHttp. setRequestHeader ('content-type', 'application/x-www-form-urlencoded ');
  11. XmlHttp. onreadystatechange = function (){
  12. If (xmlHttp. readyState = 4 ){
  13. Updatepage (xmlHttp. responseText );
  14. }
  15. }
  16. XmlHttp. send (strURL );
  17. }
  18. Function updatepage (str ){
  19. If (str = "yes "){
  20. Alert ("Welcome User ");
  21. } Else {
  22. Alert ("Invalid Login! Please try again! ");
  23. }
  24. }
  25. Function call_login (){
  26. Var username = parameter doc ument. f1.username. value;
  27. Var password = parameter doc ument. f1.password. value;
  28. Var url = "login. php? Username = "+ username +" password = "+ password;
  29. PostRequest (url );
  30. }

PHP script login. php:
 

PHP code
  1. $ Username = $ _ GET ["username"];
  2. $ Password = $ _ GET ["password"];
  3. If ($ username = "admin" & $ password = "admin "){
  4. Echo "yes ";
  5. } Else {
  6. Echo "No ";
  7. }
  8. ?>

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.