简体   繁体   中英

jquery: function parameter is undefined in success callback

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
 }
});
}

在此输入图像描述

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
  }
});
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM