I have a function that is called to create a row in a table with row data being passed in. Within that function I need to call an AJAX function to retrieve data related to one of the cells in the row. While I get the variable via the .done method I'm struggling to see how to make it available in the fctn1
function.
function fctn1( rowdata ) {
var url = "https://...";
var state;
fetchData(url).done(function(data) {
var state = data.items.state;
console.log(state); // logs correct state
});
console.log(state); // undefined
// fctn1 code creates table row using rowdata and 'state' variable from AJAX call
}
function fetchData(url) {
// Return the $.ajax promise
return $.ajax({
url: url,
type: "GET",
contentType: "application/json",
dataType: 'json',
});
}