tags:

views:

197

answers:

3

I am trying to load a file (http://domain.com/v2/inc/review.php) from a subdomain (http://resort.domain.com) using jquery. Although I use the full location it refuses to load. Does anyone know how to get it to work?

$("#resort").load("http://domain.com/v2/inc/review.php");
+1  A: 

To make things short. You can't load remote domain content with ajax. This a restriction applied by all browsers and is called the Same origin policy. So trying to load data from a different subdomain is already a violation of the same origin policy.

The only thing you can do to load data from a different domain is use json

jQuery.getJSON()


@Matt's comment:

I was indeed thinking about JSONP. Which is exactly what jQuery getJson uses if the url is on a remote server

From the documentation:

If the specified URL is on a remote server, the request is treated as JSONP instead. See the discussion of the jsonp data type in $.ajax() for more details.

jitter
Not technically correct. Making an AJAX call and returning JSON will still get affected. Perhaps you're thinking of JSONP?
Matt
Yes I meant JSONP see expanded answer
jitter
A: 

In the Javascript for the page on http://resort.domain.com, do...

document.domain = "domain.com";

Then you should be fine.

Matt
A: 

You are running in to the security restriction that browsers have with doing an ajax request from a different domain. One option is to proxy your request through your current domain. Something like Simple PHP Proxy would work for you.

PetersenDidIt