Home  >  Article  >  Web Front-end  >  Ajax asynchronously requests the mouse to leave the input text box problem

Ajax asynchronously requests the mouse to leave the input text box problem

一个新手
一个新手Original
2017-09-20 09:24:422178browse

<%@ 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(&#39;MSIE&#39;)>0){
	xhr=new ActiveXObject(&#39;Microsoft.XMLHTTP&#39;);
 }else{
	xhr=new XMLHttpRequest();
 }
return xhr;
 */
 try{
	  return new ActiveXObject(&#39;Microsoft.XMLHTTP&#39;);
  }catch(e){
   }
  try{
	  return new XMLHttpRequest();
  }catch(e){
  }
   
};
//获得id属性值简单分装方法
function $(id){
	  return document.getElementById(id);
};
window.onload=function(){
	$(&#39;username&#39;).onblur=function(){
     	var username=$(&#39;username&#39;).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>

The above is the detailed content of Ajax asynchronously requests the mouse to leave the input text box problem. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn