i want to get data from other sites using javascript executed from my website.
6 Answers
In general, unless they expose the data with JSON-P, you can't thanks to the security considerations imposed by the same origin policy.
Recent browsers support a permissions system where a remote site can allow JavaScript running on a remote site to make a request. Flash provides a similar system, so can act as an intermediary. Both of these require the cooperation of the remote site.
The usual work around is to use a proxy service, either running on your own system (so JS makes the request to the same server, which fetches the data from the remote site) or a third-party service like YQL.

- 914,110
- 126
- 1,211
- 1,335
Javascript is limited by the same-domain security policy. The only way to get data from other sites is to use JSONP or build a proxy on your own host that lets you curl
content from other sites.

- 19,661
- 3
- 34
- 43
-
I'm pretty sure there's other PHP ways besides `curl` also, but I'm too lazy to look for them - `file_get_contents` of course springs to mind. – Ben Jan 03 '11 at 08:45
-
Sure, but that's just shorthand for `curl`. Not part of the question though, the user asked whether he/she could fetch content from other domains. – Klemen Slavič Jan 04 '11 at 13:44
Use jQuery:
$.post( 'http://some.website.com/file.js', function(result){
alert(result);
});
You may not fetch anything but JavaScript or JSON.
Or try this answer: How do I send a cross-domain POST request via JavaScript?
It has to be done server side - send an ajax request, run the PHP you want, and check the responseText
property to see the results.
That really depends on what you mean by "data". Try using AJAX if its just for simple requests.

- 4,186
- 2
- 25
- 44