Note. You cannot use Ajax to access another domain. (This is called a single domain policy .)
However, the StackOverflow API supports JSONP callbacks, so here is the solution:
Download the script using the <script> .
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;
Set up the callback function:
function soResponse(obj) { alert(obj.users[0].reputation); }
Download it!
load_script('http://api.stackoverflow.com/1.0/users/401025/?jsonp=soResponse');
Jacob Relkin
source share