Needless to say, the code is as follows:
ajax.jsp Code
<%@ page language= "java" import= "java.util.*" pageencoding= "GBK"%>
<script language= "JavaScript" >
var xmlHttp;
function Createxmlhttp () {
if (window. XMLHttpRequest) {
XmlHttp = new XMLHttpRequest ();
}else{
XmlHttp = new ActiveXObject ("Microsoft.XMLHTTP");
}
}
function GetInfo () {
Createxmlhttp ();
Xmlhttp.open ("POST", "Allarea.xml");
Xmlhttp.onreadystatechange = Getcitycallback;
Xmlhttp.send (NULL);
}
function Getcitycallback () {
if (xmlhttp.readystate = = 4) {
Alert ("------ooo--");
if (Xmlhttp.status = = 200) {
var allarea = Xmlhttp.responsetext;
alert (Allarea);
}
}
}
</script>
<body onload = "GetInfo ()" >
<form action= "" method= "POST" >
</form>
</body>
Allarea.xml file
<?xml version= "1.0" encoding= "UTF-8"?>
<allarea>
<area>
<id>1</id>
<title> Beijing </title>
</area>
<area>
<id>2</id>
<title> Shanghai </title>
</area>
<area>
<id>3</id>
<title> Shenzhen </title>
</area>
</allarea>