<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<script>
function f1(){
var username=document.getElementById('username').value;
<span style="color:#ff0000;"> //对传递的特殊的特殊符号进行编码处理
username=encodeURIComponent(username);</span>
//1.创建ajax对象
if(typeof ActiveXObject!="undefined")
{
var xhr=new ActiveXObject("Microsoft.XMLHTTP");//最原始方式
var xhr=new ActiveXObject("Msxml2.XMLHTTP");//升级
var xhr=new ActiveXObject("Msxml2.XMLHTTP.3.0");//升级
var xhr=new ActiveXObject("Msxml2.XMLHTTP.6.0");//升级
}
else
{
var xhr=new XMLHttpRequest();
}
//设置事件
xhr.onreadystatechange=function(){
if(xhr.readyState==4)
{
alert(xhr.responseText);
}
}
//连接服务器
xhr.open(<span style="color:#ff0000;">'get','2.php?name='+username,true</span>);//异步传输:同一时间执行多个进程
//发送请求
xhr.send<span style="color:#ff0000;">(null</span>);
}
</script>
</head>
<body> //失去焦点触发
用户名: <input type="text" <span style="color:#ff0000;">id="username"</span> name="username" <span style="color:#ff0000;">οnblur="f1()" </span>/>
<input type="password" id="pws" name="password"/>
</body>
</html>
//2.php
<?php
print_r($_GET);
?>
注意1.特殊符号的编码处理
2.open,url参数的添加