简体   繁体   English

jquery:函数参数在成功回调中未定义

[英]jquery: function parameter is undefined in success callback

I am trying to access graphList within success callback, but graphList is undefined. 我试图在成功回调中访问graphList,但graphList未定义。 I referred this StackOverflow post. 我提到了这个 StackOverflow帖子。 However, I am not able to access elem. 但是,我无法访问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 添加了如下创建getGraphList函数,我可以在成功回调中访问getGraphList

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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