I was just curious about cross-domain AJAX and I wanted to know how it works
A server-side script on your domain is used to load and output the content, then the XMLHttpRequest object reads that file like normal. A simple example (not that you should use this, of course; much more checking is required) is:
Code:
<?php
// golden.php
die(file_get_contents($_GET['url']));
?>
By open()ing:
Code:
xhr.open("GET", "golden.php?url=" + encodeURIComponent("http://www.google.com/"), true);
that file with the correct GET variable, any page on the Internet can be retrieved.
Bookmarks