I want to get some value from my callback. Yes this was asked a lot of times in SO. But I can't find any solution.
dostuff = function(callback) {
$.ajax({
type: 'GET',
url: filepath,
success: function(data) {
var value = data.split("\n");
var line = Math.round(Math.random() * (value.length - 1)) + 1;
callback(value[line]);
}
});
}
function myCallback(line){
console.log(line);
}
obj.dostuff(myCallback);
That works fine and logs the value. But I want the code to look something like that:
function myCallback(line){
return line;
}
console.log(obj.dostuff(myCallback));
But that logs "undefined". I don't get it.