I am making jquery calls to get and getJSON, but cannot access returned values outside of callback function. How can I access the returned data?
var firstid;
var nextid;
$.get(callUrl, function(data) { // call to add node
var n = data.indexOf("id-");
var m = data.indexOf("id-");
firstid = data.substr(n+3,m - (n+3));
nextid = data.substr(m+3);
alert("firstid:" + firstid); // returns correct value
});
alert("firstid:" + firstid); // returns undefined for firstid
how can I get firstid outside the function?
ALL AJAX CALLS ARE ASYNCHRONOUS
SO you need to use callbacks. anything outside that will return
undefined.