日期:2014-05-16 浏览次数:20632 次
protected void Page_Load(object sender, EventArgs e) { Response.Clear(); Response.ContentType = "text/xml";//设置输出的格式为XML Response.Charset = "UTF-8";//设置输出的编码为UTF-8 this.GetXmlData(); } private void GetXmlData() { StringBuilder xmlData = new StringBuilder(); xmlData.AppendLine(@"<?xml version='1.0' encoding='UTF-8' ?>"); xmlData.AppendLine(@"<response>"); xmlData.AppendLine(@"<res>1111</res>"); xmlData.AppendLine(@"</response>"); Response.Write(xmlData.ToString()); }
if (window.XMLHttpRequest) { //Mozilla 浏览器 XMLHttpReq = new XMLHttpRequest(); } else if (window.ActiveXObject) { // IE浏览器 try { XMLHttpReq = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { } } } var url = "WebForm5.aspx"; XMLHttpReq.open("GET", url, true); XMLHttpReq.onreadystatechange = function () { if (XMLHttpReq.readyState == 4) { // 判断对象状态 if (XMLHttpReq.status == 200) { // 信息已经成功返回,开始处理信息 alert(XMLHttpReq.responseXML.getElementsByTagName("res").length); } else { //页面不正常 window.alert("您所请求的页面有异常。"); } } }; //指定响应函数 XMLHttpReq.send(null); // 发送请求
protected void Page_Load(object sender, EventArgs e) { Response.Clear(); Response.ContentType = "text/xml";//设置输出的格式为XML Response.Charset = "UTF-8";//设置输出的编码为UTF-8 this.GetXmlData(); Response.End();////////// }