<%@ page language="java" contenttype="text/html; charset=utf-8"
pageencoding="utf-8"%>
<!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>ajax1</title>
<script>
//创建浏览器对象
function createxhr(){
//判定浏览器类型处理第一种方法
/* var xhr;
var str=window.navigator.useragent;
if(str.indexof('msie')>0){
xhr=new activexobject('microsoft.xmlhttp');
}else{
xhr=new xmlhttprequest();
}
return xhr;
*/
try{
return new activexobject('microsoft.xmlhttp');
}catch(e){
}
try{
return new xmlhttprequest();
}catch(e){
}
};
//获得id属性值简单分装方法
function $(id){
return document.getelementbyid(id);
};
window.onload=function(){
$('username').onblur=function(){
var username=$('username').value;
var xhr=createxhr();
xhr.onreadystatechange=function(){
if(xhr.readystate==4&&xhr.status==200){
};
}
xhr.open("get","/ajax2?username="+username);
xhr.send(null);
}
};
</script>
</head>
<body>
用户名:<input type="text" name="username" id="username"/>
</body>
</html>
以上就是ajax异步请求鼠标离开输入文本框的问题 的详细内容。