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

前端 未结 6 1348
迷失自我
迷失自我 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:38

    var context;
    $.ajax({
      url: 'file.json',
      async: false,
      dataType: 'json',
      success: function (json) {   
        assignVariable(json);
      }
    });
    
    function assignVariable(data) {
      context = data;
    }
    alert(context);
    

提交回复
热议问题