Home > Article > Web Front-end > Ajax asynchronously requests the mouse to leave the input text box problem
<%@ 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>
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!