Hi all,
Below is a small example of calling some JSON, displays a list via the Mustache template engine, everything's good.
The trouble is. I'd like to make another AJAX call and get some other JSON. But. I need the value from one of the variables inside the success
method passed/available to the then
method.
How do we get the snippet value from success?
var people = "https://swapi.co/api/people/";
$.getJSON(people, function(data) {
var template = $('#results_tpl').html();
var html = Mustache.render(template, data);
$('#results').html(html);
})
.success(function() {
var snippet = "Hello Barry, working with JSON.";
console.log(snippet);
})
.then(function() {
console.log(snippet); //snippet is not defined
//...get some other JSON based on the snippet value
});
For reference if needed Codepen
Thanks, Barry