Click to See Complete Forum and Search --> : is there a solution to corss domain Ajax


cgishack
01-08-2007, 06:12 PM
Is there any solution to accessing data from another domain using Ajax/JS ?
I thought of the hidden frame trick, but it would require a lot more coding for me :( . less code = happy!

Any suggestions welcome,

Drew

Overstatement
01-08-2007, 06:21 PM
Wasn't someone talking about taking the data from your PHP script which takes the data from someone else's site?

cgishack
01-08-2007, 06:22 PM
I never saw the post.

Overstatement
01-08-2007, 06:24 PM
I don't understand Ajax so I didn't understand those guys but it makes sense in theory, doesn't it?

felgall
01-08-2007, 06:24 PM
There is no problem with cross domain access server side. Get the Javascript on your site to call server side processing on your site. That server side processing then contacts the other site and retrieves the required information which it then passed back to the browser.

cgishack
01-08-2007, 06:32 PM
Would that not slow down the whole processing time ?
Double it up ?

Overstatement
01-08-2007, 06:38 PM
Found it! (http://www.webdeveloper.com/forum/showthread.php?t=133781). ricp saved the data in his(her?) PHP script and only asked the other server if the current data was out of date.

ricp
01-08-2007, 06:56 PM
Him :) .. Just because I have Miffy as an avatar doesn't make me less of a man you know! :p

Anyway.. there isn't a way to do it client side alone. In fact the only method of having cross domain scripting of any sort is by using an externally referencing script include tag..


<script type="text/javascript" src="http://not-on-my-domain.com/some-server-side-page.aspx"></script>


I've used aspx as an example but it just needs to point to some generated js from a remote server. Because the script tag is in the scope of the page it's in you can access it's content.

Of course the "served" content has to be valid JavaScript, which is why it is favoured by a lot of people who like JSON (http://www.json.org/js.html).