views:

130

answers:

2

Hi, I'm using this Ajax script (http://www.dhtmlgoodies.com/index.html?whichScript=ajax-dynamic-content) to load content from an aspx page on another server than the page calling the content. So far I've learned that this is a no go. The problem seems to be that when using an absolute link to content the script fails as apposed to using a relative link.

I've searched the web for about 10 hours now, and I still haven't found what I'm looking for. I'm in need of some expert help here. Appreciate any help.

Best regards Nano

A: 

It doesn't matter if the URL is absolute or relative, all that matters is that the server is different. See the Same Origin Policy.

The workarounds are:

  1. Proxy the data through URLs on the same host as the page loading the script
  2. Use JSON-P as the data format
  3. Use something which has options for cross domain requests (e.g. Flash)
David Dorward
Thank you both Peter and David for quick response.Clearly you guys are a bit more techy than I am. I'm not sure what "proxy the data through URL's..." means. I have read about jsonp on http://api.jquery.com/jQuery.getJSON/. I hope that's the best place to read about jsonp.Anyway, it seems like I'm in for a long night understanding jsonp and writing the necessary code. Thank you for answering my question!
Nano
Proxy the data means "Use Ajax to fetch data from your local server. That data is put together by making a request (using a server side script) to the third party server.
David Dorward
The jQuery documentation is a terrible place to learn about JSON-P — not least because it assumes you know what JSON-P is already.
David Dorward
Do you have any recommendations where to best learn the use of JSON-P?
Nano
The link I provided in my original answer
David Dorward
Of course. Thank you!
Nano
So, after much fuzz and reading, and testing, and reading about JSON and proxy, I came across this solution<?php$content= file_get_contents('http://www.domain.com');echo $content;?>So simple, it works just fine, and heck of a lot easier than JSON and proxy. The 10,000 dollars question remains though. Is it something wrong with this method for cross domain requests?
Nano
No! I don't think so. For future reference to you all. Simplicity!
Nano
@Nano - That **is** proxying the data through your own server!
David Dorward
Really? Ok then. I was primarily concerned by your answer including Ajax into the equation. I'm not complaining here, but the fact of the matter is that you "tech-guys or girls" most of the time aren't explaining or giving advice as much as you just throw out the first thing that pops out of your mind based on your own expertise. Keep in mind the possibility of a poor ignorant noob on the other side of the table. Cheers!
Nano
A: 

You can't load content from another domain this way (browsers don't allow it for security reasons). You have options though. If you really need to do cross-domain AJAX (that's what its called) you might want to look into using jQuery and JSON-P for your AJAX. There's also several options with flash, iframes and proxies (none of them are simple).

Peter