How can I return a variable from a $.getJSON function

前端 未结 6 1349
迷失自我
迷失自我 2020-11-27 03:01

I want to return StudentId to use elsewhere outside of the scope of the $.getJSON()

j.getJSON(url, data, function(result)
         


        
6条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-27 03:32

    If you wish delegate to other functions you can also extend jquery with the $.fn. notation like so:

    
    var this.studentId = null;
    
    $.getJSON(url, data, 
        function(result){
          $.fn.delegateJSONResult(result.Something);
        }
    );
    
    $.fn.delegateJSONResult = function(something){
      this.studentId = something;
    }
    
    
    

提交回复
热议问题