<!DOCTYPE html> <html> <head> <title></title> <meta charset="utf-8" /> <script type="text/javascript"> function login(){ //第一步:建立ajax對象 var ajax = new XMLHttpRequest(); //設置監聽函數 ajax.onreadystatechange = function(){ if (ajax.readyState==4 && ajax.status == 200){ var res = ajax.responseText; alert(res); } } //準備發送數據 ajax.open("get","./user.php?username=zhangsan&password=123456",true); //發送數據 ajax.send(null); } login(); login(); login(); </script> </head> <body> </body> </html>
user.phpjavascript
<?php $username =$_GET['username']; $password =$_GET['password']; //處理數據 echo "註冊成功"; ?>