Retrieve JSON with StackOverflow API

Note: You cannot use Ajax to access another domain. (This is called the same-domain policy.)

However, the StackOverflow API supports JSONP callbacks, so here is a solution:

Load in the script via a <script> tag.

Create a function that does just that:

function load_script(src) {
   var scrip = document.createElement('script');
   scrip.src = src;
   document.getElementsByTagName('head')[0].appendChild(scrip);
   return scrip; //just for the heck of it
}

Set up the callback function:

function soResponse(obj) {
   alert(obj.users[0].reputation);
}

Load it!

load_script('http://api.stackoverflow.com/1.0/users/401025/?jsonp=soResponse');