window.onload = function(){
document.getElementById('username').onblur = function(){
var name = document.getElementById('username').value;
name = encodeURIComponent(name); // 编码
var request = new XmlHttpRequest();
request.open('post', 'demo.php');
request.onreadystatechange = function(){
if (request.readystate == 4 && request.status == 200) {
var str = request.responseText();
alert(str);
}
}
request.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
request.send('name='+name);
}
}