Can't access global variable in jQuery $.get within function

后端 未结 3 1801
甜味超标
甜味超标 2021-01-18 10:25

Below is some code I\'m having trouble with. Basically, I\'m defining an empty array as a global variable (var playlist = []) and then trying to add elements to it within a

3条回答
  •  生来不讨喜
    2021-01-18 10:40

    Chances are, playlist is getting used before $.get returns - as ajax calls are asynchronous. It works within the success callback because that gets fired once the request has completed, so it will contain the data you expect.

提交回复
热议问题