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

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

    Even simpler than all the above. As explained earlier $.getJSON executes async which causes the problem. Instead of refactoring all your code to the $.ajax method just insert the following in the top of your main .js file to disable the async behaviour:

     $.ajaxSetup({
       async: false
     });
    

    good luck!

提交回复
热议问题