Search code examples
javascriptjqueryxmlajaxsame-origin-policy

Same Origin Policy, Javascript/jQuery AJAX and retrieving an RSS XML feed


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?


Solution

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

    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.