同源策略,使用Javascript / jQuery的AJAX和检索一个RSS XML提要 [英] Same Origin Policy, Javascript/jQuery AJAX and retrieving an RSS XML feed

查看:132
本文介绍了同源策略,使用Javascript / jQuery的AJAX和检索一个RSS XML提要的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我碰到一个问题,使用jQuery来获取RSS订阅源位于外部域。这是工作在Safari,但其他浏览器会错误的,因为同源策略的限制(也记载有关$阿贾克斯()函数)。

I came across a problem using jQuery to retrieve an RSS feed located on an external domain. It was working in Safari but other browsers would error because of Same Origin Policy restrictions (which are also documented about the $.ajax() function).

想知道我是怎么定的呢?

Wanna know how I fixed it?

推荐答案

有三种方法可以绕过同源策略:

There are three ways to get around the Same-Origin Policy:

  1. 在代理 - 草莓Sheurbert那样,完全有效的,但浪费带宽和计算能力
  2. JSONP - 通过脚本加载数据标记。需要从源代码的网站合作,基本的hackish而笨拙。
  3. CORS - 正确的方式,优雅,细致入微,但需要<从源网站合作EM>很多的,不与旧的浏览器。
  1. Proxy -- as Strawberry Sheurbert did, perfectly effective but a waste of bandwidth and computing power
  2. JSONP -- loading the data through the script tag. Needs cooperation from source website and basically hackish and clumsy.
  3. CORS -- the "right" way, elegant and nuanced, but needs a lot of cooperation from source website and doesn't work with older browsers.

您支付你的钱,你需要你的机会。

You pays your money and you takes your chance.

这篇关于同源策略,使用Javascript / jQuery的AJAX和检索一个RSS XML提要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆