1

I am trying to access graphList within success callback, but graphList is undefined. I referred this StackOverflow post. However, I am not able to access elem. Any help would be appreciated.

getGraphData = function (graphList) {
 $.ajax({
 type: "GET",
 url: 'someURL',
 beforeSend: function(xhr){},
 success: function(result) {
   console.log(result);
   console.log(graphList);//undefined
 }
});
}

enter image description here

Community
  • 1
  • 1
user1556718
  • 91
  • 1
  • 9

1 Answers1

0

Added creating getGraphList function as below, I can access getGraphList inside success callback

var graphList;
var promise = graphInit(response);
promise.done(function(data){
  getGraphData(data.graphs)
}

graphInit = function(response,graphList){
  getGraphList = function(){return response.graphs;}
}

getGraphData = function (graphList) {
  $.ajax({
  type: "GET",
  url: 'someURL',
  beforeSend: function(xhr){},
    success: function(result) {
    console.log(result);
    console.log(graphList);//undefined
    graphList = getGraphList();//available
  }
});
}
user1556718
  • 91
  • 1
  • 9