html5中文学习网

您的位置: 首页 > 网络编程 > AJAX相关 » 正文

ajax的 responseXML返回接受 asp_AJAX相关_脚本之家

[ ] 已经帮助:人解决问题
第一个文件   index.asp
<script language="javascript">
var xmlHttp = false;    //ajax使用
try {
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
  try {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e2) {
    xmlHttp = false;
  }
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
  xmlHttp = new XMLHttpRequest();
}
function callserver()
{
 var url = "index.asp";
 xmlHttp.open("POST",url,true);
 xmlHttp.onreadystatechange = update;
    xmlHttp.setrequestheader("content-type","application/x-www-form-urlencoded");
 xmlHttp.send(null);
}
function update()
{
 if(xmlHttp.readystate==4)
 {
  var xmldoc=xmlHttp.responseXML
  var info = xmldoc.getElementsByTagName("info")[0].text;
  alert(info);
 }
}
callserver();
</script>

 

第二个   login.asp

<%
Response.ContentType="text/xml"
response.Write("<?xml version='1.0' encoding='GB2312' ?>")
response.Write("<root>")
response.Write("<info>love you</info>")
response.Write("</root>")
%>
(责任编辑:)
推荐书籍
推荐资讯
关于HTML5先行者 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助