3

Possible Duplicate:
load content from external page into another page using ajax/query

May be I just don't get something.

I want to get html page from other site, let it be http://www.server.com/somepage/param

In my js code:

  var url = "http://www.server.com/somepage/param";
   $.get(url, callback);

Chrome says "Failed to load resource".

What is wrong?

0

2 Answers 2

6

You're running into restrictions imposed by the Same Origin Policy. In short, AJAX calls to a different domain are prohibited and will always fail.

You need to either use JSONP (mostly applicable to data returned by APIs) or proxy the request through your own server/domain.

Sign up to request clarification or add additional context in comments.

7 Comments

Well, but I've got a chrome extension, and it makes such requests, and get the information from site I need. How? I looked at js source it uses jQuery.
It uses special permissions given to Plugins. Here's an excellent writeup about how to implement this: sarajchipps.com/2011/01/…
Oh, thank you very much for your answer. Sadly that, this simple solution works only in crhome, It seems that I need to find a way to use proxy solution with my ROR 3.1 server
But what about this document: w3.org/TR/cors (infromation from here merbist.com/2011/09/14/how-to-cross-domain-ajax-in-a-ruby-app - However, most browsers (IE 8+, Firefox 3.5+, Safari 4+, Chrome) implement a simple way to allow cross domain requests as defined in this w3C document.)
Well, can you get the remote host to send a Access-Control-Allow-Origin: http://yourhost.com header?
|
6

The simple answer is, no, this is not possible. Cross Domain AJAX is not allowed. However, you can find a (working) workaround here:

http://jquery-howto.blogspot.com/2009/04/cross-domain-ajax-querying-with-jquery.html

More details about cross-domain ajax requests: Dashboard Cross-domain AJAX with jquery

1 Comment

Well, but I've got a chrome extension, and it makes such requests, and get the information from site I need. How? I looked at js source it uses jQuery.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.