.net 的ajax页面 怎么返回xml

2025-12-03 17:22:29
推荐回答(2个)
回答1:

你可以把xml内容作为普通的文本传回:
var xml = @"



select * from table
]]>


";
Response.Write(xml);

这样在前台:
$.get("Handler1.ashx",
{
"r": Math.random(),
"其他参数": "参数值"
},
function (strXml) {
alert(strXml);
}
);
strXml就是xml的内容了。

回答2:

context.Response.ContentType = "application/xml";
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("1");
sb.Append("");
sb.Append("
");
context.Response.Write(sb.ToString());
context.Response.End();