Reputation: 663
The function info()
appends my document with images (what is done perfectly), but I want it also to write variable next
with information from json so I can use it outside of info()
var next;
var info = function(link) {
$.getJSON(link, function(json) {
$.each(json.data.children, function(i, things) {
$("#threadlist").append('<img src="' + things.data.url + '">');
});
next = json.data.after;
});
};
Upvotes: 0
Views: 98
Reputation: 169391
Welcome to callbacks
function info(link, callback) {
$.getJSON(link, function(json) {
$.each(json.data.children, function(i, things) {
$("#threadlist").append('<img src="' + things.data.url + '">')
})
callback(json.data.after)
});
}
info("url", function (next) {
...
})
Upvotes: 4