views:

2412

answers:

3

I am using CakePHP for my project, and I am generating XML views so that I can interact with them (CRUD) from an external website. There is authentication required on the CakePHP website.

Essentially, I want to view "http://mycakeapp.com/posts/views/1.xml" from "http://www.example.com"

However, I get this error when using jQuery's ajax function: Access to restricted URI denied" code: "1012. It seems from googling that maybe trying JSONP is an option .. but its not native to cake and hence I'd rather use xml :(

I've tried using an iframe: it loads up the login screen - and after I login, it loads the current page (e.g. "http://www.example.com")! Even though the iframe source is "http://mycakeapp.com/posts/views/1.xml"

Has anyone tackled this problem before?

Update: To be a bit more specific, I would like to create a bookmarklet that communicates with my website (built on CakePHP), so a url proxy method won't work (but thanks for the suggestion)

+3  A: 

Simply make a proxy script in PHP. let the Ajax request your proxy script, have your proxy script "forward" your request across the domain by using cURL, simply have your proxy script echo out the response you get from your cURL request, and you will be good to go.

mmattax
+1  A: 
ianmjones
Hey Ian,Thanks for the detailed response, I'm currently trying to implement it. I was wondering if this would work if http://www.example.com is a website that I don't run but they want to get access to my xml? Because it seems that the proxy php needs to be placed there and not on my site?
828
Hi 828, yes, the proxy script needs to be on the server that is going to then ask another server for the data.
ianmjones
A: 

JSONP is definitely what you're looking for.

Maybe the following page could help you: http://www.ibm.com/developerworks/xml/library/x-xml2jsonphp/

Julian Aubourg