<html> <head> <title>AjaxTest</title> <script> var xmlHttp; function createXMLHttpRequest() { if(window.ActiveXObject) { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } else if(window.XMLHttpRequest) { xmlHttp = new XMLHttpRequest(); } } function startRequest() { createXMLHttpRequest(); try { xmlHttp.onreadystatechange = handleStateChange; xmlHttp.open("GET", "data.xml", true); xmlHttp.send(null); } catch(exception) { alert("xmlHttp Fail"); } } function handleStateChange() { if(xmlHttp.readyState == 4) { if (xmlHttp.status == 200 || xmlHttp.status == 0) { var root = xmlHttp.responseXML.documentElement; try { var info = root.getElementsByTagName("info")[0]; alert(info.getAttribute('type')); } catch(exception) { alert("The node is not exist"); } } } } </script> </head> <body> <div> <input type="button" value="AjaxTest" onclick="startRequest();" /> </div> </body> </html>


XML code
<?xml version="1.0" encoding="GB2312"?> <root> <info type="student"></info> </root>

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-26
猜你喜欢
  • 2022-12-23
  • 2021-12-03
  • 2022-12-23
  • 2021-06-22
  • 2022-12-23
相关资源
相似解决方案