// 输出数据 // title: 输出数据的标题 // states: 输出数据来源 ********************************************************/ function outputList(title,states) { var out = title; var currentState = null; // 初始化省份对象 for (var i = 0; i < states.length; i++) // 列出Ststes对象的所有数据,生成输出串 { currentState = states[i]; // 取得当前的省份 // 生成输出HTML字符串 out = out + "<ul><font face='仿宋_GB2312'><span style='font-size: 9pt'>"; out = out + "<li>" + currentState.childNodes[0].nodeValue + "</li>"; out = out + "</span></font></ul>"; } // 取得输出串的对象,输出生成的字符串 var test = document.getElementById("test"); test.innerHTML = out; }
5、完整示例文件
<!DOCTYPE html PUBLIC "-//W3C//DTD XHML 1.0 Strict//EN" "http://www.w3.org/TR/xHML/DTD/xhtml-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">
<head> <meta http-equiv="Content-Type" CONTENT="text/html; charset=gb2312"> <meta http-equiv="Cache-Control" CONTENT="no-cache"> <meta http-equiv="Pragma" CONTENT="no-cache"> <meta http-equiv="Expires" CONTENT="0">
<title>AJAX 测试</title> <script type="text/javascript"> ///// 创建XMLHttpRequest对象 var xhr; var requestType = "";
//xhr = new XMLHttpRequest();
function createXMLHttpRequest() { if (window.ActiveXObject) { xhr = new ActiveXObject("Microsoft.XMLHTTP"); } else if (window.XMLHttpRequest) { xhr = new XMLHttpRequest(); } } ///// XML文档处理 function startRequest(requestedList) { if (xhr) { requestType = requestedList; createXMLHttpRequest(); xhr.onreadystatechange = handleStateChange; xhr.open("GET","../ajax/paraseXML.xml",true); xhr.send(null); } else alert("XMLHTTPREQUEST IS FALSE"); }
[1] [2] 下一页
function handleStateChange() { if (xhr.readyState == 4) { if (xhr.status == 200) { if (requestType == "north") { listNorthStates(); &n 上一页 [1] [2] [3] [4] 下一页
|