In the process of learning Ajax requests using jQuery, I tried to load google home page on the click of a link. So I wrote something like:
$(\"#ajax\").click
It's worth noting that you are not completely precluded from cross-domain requests in javascript.
As of jQuery 1.2, you can load JSON data located on another domain if you specify a JSON-P callback and the URL that you call supports JSON-P output.
The following example is straight from the jQuery docs. It grabs the last four flickr pics tagged with "cat".
$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?tags=cat&tagmode=any&format=json&jsoncallback=?",
function(data){
$.each(data.items, function(i,item){
$("
").attr("src", item.media.m).appendTo("#images");
if ( i == 3 ) return false;
});
});
You can read the docs here: http://docs.jquery.com/Ajax/jQuery.getJSON#urldatacallback
Personally I use it to pull in my latest tweets on my blog without having to build it into my server-side code. That also has the added benefit of not having to write error handling code for the often spotty API service from Twitter. Just view source on my blog if you wanna see it: http://joreteg.com