Make AJAX “get” function synchronous / how to get the result?
I'm experiencing a problem of $.get function. The url contains JSON my code: xyz = null $.get('http://www.someurl.com/123=json', function(data) { var xyz = data.positions[0].latitude; }); alert(xyz); //some more code using xyz variable I know that xyz will alert a null result because the $.get is asynchronous . So is there any way I can use the xyz outside this get function? The real answer is NO , but you can use this: function useXYZ(){ alert(xyz); } xyz = null $.get('http://www.someurl.com/123=json', function(data) { xyz = data.positions[0].latitude; useXYZ(); }); get is a shortcut. You can