Setting local variable in a JavaScript callback function

后端 未结 5 1896
余生分开走
余生分开走 2021-01-02 11:33

I\'m relatively new to JavaScript and I thought I knew how callback functions worked but after a couple of hours of searching the web I still do not understand why my code i

5条回答
  •  北海茫月
    2021-01-02 12:16

    AJAX is asynchronous. You are setting the array variable, but not until after that debug executes. Making an AJAX call sends a request but then continues on in the code. At some later point, the request returns and your success or error functions execute.

提交回复
热议问题