您的位置:首页 > 理论基础 > 计算机网络

Cross Domain XmlHttpRequests (http://benreichelt.net/blog/2005/4/11/Cross-Domain-XmlHttpRequests-Ajax/)

2008-06-17 21:08 633 查看


Cross Domain XmlHttpRequests (Ajax)

11 Apr, 2005
Uncategorized

One problem you run into when using client side xml calls is the

issue of getting some xml from a different domain. Making a

cross domain request is simply denied in Firefox, and I believe it is

denied in SP2 IE, however pre-SP2 you were just alerted to the fact

that a cross domain request was being made. On some of our pages

we want to include Yahoo news feeds that

relate to the content on the page. Since we couldn�t just make

the request (Response.Redirects also do not work), I wrote a little

page that takes in another url as a querystring parameter, makes its

own web request to that page, and streams the content down to the

client. This allows you to get any feed from any domain you want,

so it can come in pretty handy for the scenario I described

above. Here is the code from the intermediate page:

UPDATE:

Sorry for the poor formatting, I guess I’m not using CopySourceAsHTML

in the correct way. If you view the post on my blog page, the

formatting is intact.

8

9 namespace MyApp.Web.Services

You�ll notice in the �GetExternalFeed� method, I�m UrlDecoding the

querystring parameter to create a valid url from the string. Make

sure to use the javascript �escape

function on your querystring parameter before making the request,

otherwise any �&� in the url will be lost and your url will be

invalid.

So thats all there is to it, now you can get xml feeds from anywhere on the web!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐