求组:如何读取xml的值
用ajax读取ashx返回的值如下,请问如何获取 3 这个值,谢谢了
<?xml version="1.0" encoding="utf-8"?>
<int xmlns="http://tempuri.org/">3</int>
[解决办法]
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
var xmlDoc = null, xmlhttp = null;
function loadXML() {
xmlhttp = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHttp");
if (xmlhttp == null) {
alert("你的浏览器不支持 XMLHttpRequest");
return;
}
xmlhttp.open("GET", "CoverHandler.ashx?" + Date.parse(new Date()), true);
xmlhttp.onreadystatechange = getmessage;
xmlhttp.send(null);
}
function getmessage() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
xmlDoc = xmlhttp.responseXML.documentElement;
if (xmlDoc == null) {
alert("返回的数据不正确。");
return;
}
alert(xmlDoc.firstChild.nodeValue);
}
}
</script>
</head>
<body onload="loadXML()">
</body>
</html>
<%@ WebHandler Language="C#" Class="CoverHandler" %>
using System;
using System.Web;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
public class CoverHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/xml";
context.Response.Write(@"<?xml version=""1.0"" encoding=""utf-8""?>
<int xmlns=""http://tempuri.org/"">3</int>
");
context.Response.End();
}
public bool IsReusable {
get {
return false;
}
}
}