Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
61
rated 0 times [  62] [ 1]  / answers: 1 / hits: 145032  / 15 Years ago, thu, april 1, 2010, 12:00:00

I know about AJAX cross-domain policy.
So I can't just call http://www.google.com over a ajax HTTP request and display
the results somewhere on my site.



I tried it with dataType jsonp, that actually would work, but I get a syntax error (obviously because the received data is not JSON formated)



Is there any other possiblity to receive/display data from a foreign domain?
iFrames follow the same policy?


More From » jquery

 Answers
7

The only (easy) way to get cross-domain data using AJAX is to use a server side language as the proxy as Andy E noted. Here's a small sample how to implement that using jQuery:



The jQuery part:



$.ajax({
url: 'proxy.php',
type: 'POST',
data: {
address: 'http://www.google.com'
},
success: function(response) {
// response now contains full HTML of google.com
}
});


And the PHP (proxy.php):



echo file_get_contents($_POST['address']);


Simple as that. Just be aware of what you can or cannot do with the scraped data.


[#97187] Monday, March 29, 2010, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
orlando

Total Points: 413
Total Questions: 92
Total Answers: 96

Location: Mauritania
Member since Sun, Oct 17, 2021
3 Years ago
;