index.jsp 如下:
<%@page contentType="text/html;charset=gb2312" language="java" errorPage="" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language="javascript">
var http_request = false;
function send_request(url) {//初始化、指定处理函数、发送请求的函数
http_request = false;
//开始初始化XMLHttpRequest对象
if(window.XMLHttpRequest) { //Mozilla 浏览器
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {//设置MiME类别
http_request.overrideMimeType('text/xml');
}
}
else if (window.ActiveXObject) { // IE浏览器
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) { // 异常,创建对象实例失败
window.alert("不能创建XMLHttpRequest对象实例.");
return false;
}
http_request.onreadystatechange = processRequest;
// 确定发送请求的方式和URL以及是否同步执行下段代码
http_request.open("GET", url, false);
http_request.send();
setTimeout("send_request('"+url+"')",2000);
}
// 处理返回信息的函数
function processRequest() {
if (http_request.readyState == 4) { // 判断对象状态
if (http_request.status == 200) { // 信息已经成功返回,开始处理信息
var xmlobj = http_request.responseXML;
var elmDoc = xmlobj.getElementsByTagName("singleCur");
alert(elmDoc.length);
if(document.body.firstChild!=null){
document.body.removeChild(document.body.firstChild);
//alert("del");//test
}
var table=document.createElement("table");
table.setAttribute("border","1");
table.setAttribute("width","100%");
table.setAttribute("cellspacing",0);
table.setAttribute("cellpadding",0);
var head=table.createTHead();
var headrow=head.insertRow(0);
headrow.insertCell(0).appendChild(document.createTextNode("货币"));
headrow.insertCell(1).appendChild(document.createTextNode("买价"));
headrow.insertCell(2).appendChild(document.createTextNode("卖价"));
for(var i=0;i<elmDoc.length;i++) { // 循环读取
var singleCur = elmDoc[i];
row=table.insertRow(i+1);
row.insertCell(0).appendChild(document.createTextNode(
singleCur.getElementsByTagName("curid")[0].firstChild.data));
row.insertCell(1).appendChild(document.createTextNode(
singleCur.getElementsByTagName("buy")[0].firstChild.data));
row.insertCell(2).appendChild(document.createTextNode(
singleCur.getElementsByTagName("sell")[0].firstChild.data));
}
document.body.appendChild(table);
} else { //页面不正常
alert("您所请求的页面有异常。" + http_request.status);
}
}
}
</script>
</head>
<body onload="send_request('nowData.xml')">
</body>
</html>
有需要者登录http://xdqbysj.10mb.cn/
QQ:
客服一(16376208) 客服二(57293694)
先看这个有没有值