网上流传的方法基本是java方面的那种jsonp,Aspnet读取大致思路比较相似。
comment.xml
<?xml version="1.0" encoding="gb2312"?>
<root>
<comment>
<url>http://image.meimumeijia.com/product_comment/2013/08/327956_201308161103132272_small.jpg</url>
<desc>咚咚咚咚,测试测试!</desc>
</comment>
<comment>
<url>http://image.meimumeijia.com/product_comment/2013/08/327956_201sdfsdf272_small.jpg</url>
<desc>咚咚咚咚,测试测试sdfs!</desc>
</comment>
</root>
1.在A域下要使用B的comment.xml配置文件。
js
function readNewComment() {
$.ajax({
url: "/Common/Control/GetCommentHandler.ashx",
cache: false,
async: true,
dataType: "xml",
type: "Get",
timeout: 2000,
error: function (xml) {
alert("加载XML 文件出错!");
},
success: function (xml) {
$(xml).find("root").each(function () {
$(this).find("comment").each(function () {
var url = $(this).children("url").text();
var desc = $(this).children("desc").text();
alert(url + "," + desc);
})
});
}
})
}
2.在A域下创建一个一般处理程序。
ashx
string url = @"http://www.4inlook.cn/Product/comment.xml";XmlTextReader reader = new XmlTextReader(url);
XmlDocument xd = new XmlDocument();
xd.Load(reader);
context.Response.Write(xd.InnerXml);
3.在一般处理程序内请求xml,把请求的对象返回给js处理