![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
var xmlHttp;
function createXMLHTTPRequest()
{
try
{
xmlHttp = new XMLHttpRequest();
}
catch(e)
{
try
{
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
}
function startRequest()
{
createXMLHTTPRequest();
xmlHttp.onreadystatechange = handleHttpRequest;
xmlHttp.open("GET","test.xml",true);
xmlHttp.send(null);
}
function handleHttpRequest()
{
if(xmlHttp.readyState ==4)
{
alert("server:"+ xmlHttp.responseText);
}
}
</script>
<form>
<input type="button" value="Test AJAX" onclick="startRequest()"/>
</form>
</body>
</html
xml文件 test.xml内容为
hi!my name is Eping,Come form server!