当前位置: 代码迷 >> ASP.NET >> ajax中的responseXML解决方案
  详细解决方案

ajax中的responseXML解决方案

热度:4810   发布时间:2013-02-25 00:00:00.0
ajax中的responseXML
HTML code
  function callback() {            if (xmlHttp.readyState == 4) {                if (xmlHttp.status == 200) {                                      var mes = xmlHttp.responseXML.getElementsByTagName("message")[0];                     alert(mes);                    var val = xmlHttp.responseXML.getElementsByTagName("passed")[0].Text;//                    setMessage(mes, val);                    alert("b");                                     }            }        }

页面请求返回:
 
C# code
context.Response.Write("<?xml version=\"1.0\"?><response><passed>False</passed><message>You have entered an invalid date.</message></response>");


问题:1、alert(mes) 为空?取不到值。
  2、目的:取出节点的值xmlHttp.responseXML.getElementsByTagName("passed")[0].Text; 语句有没有错?

------解决方案--------------------------------------------------------
this.Response.ContentType="text/xml"
------解决方案--------------------------------------------------------
正解
------解决方案--------------------------------------------------------
还有把前台的html代码删掉只留下<%@page...
  相关解决方案