AjaxFun.js (調用函數)
function createXMLHttpRequest()
{
try
{
xmlHttp = new XMLHttpRequest();
return xmlHttp;
}
catch(trymicrosoft)
{
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
return xmlHttp;
}
catch(othermicrosoft)
{
try
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
return xmlHttp;
}
catch(failed)
{
return xmlHttp;
}
}
}
if (!xmlHttp)
{
return false;
}
}
function getResponseText(method,url,obj)
{
xmlHttp=createXMLHttpRequest();
if (xmlHttp==null)
{
return "[error]";
}
xmlHttp.open(method,url);
xmlHttp.onreadystatechange=function()
{
if(4==xmlHttp.readyState)
{
if(200==xmlHttp.status)
{
obj.innerHTML=xmlHttp.responseText;
}
}
}
xmlHttp.send();
}
test.html
<script language=javascript src="AjaxFun.js"></script>
<input type="text" name="UserName" size="20" >
<div id="UserNameHint"></div>
<script language="javascript" for="UserName" event="onblur">
obj=document.getElementById("UserName");
objHint=document.getElementById("UserNameHint");
getResponseText('get','test.asp?username='+obj.value,objHint)
</script>
test.asp 是用來檢證的,和我們常用的asp文法一樣 request.querystring就可以了。