Ajax reads the data source code in the XML file

Source: Internet
Author: User

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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.