metrampaz
metrampaz

Reputation: 663

Private-public variable;

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

Answers (1)

Raynos
Raynos

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

Related Questions