Setting local variable in a JavaScript callback function

后端 未结 5 1917
余生分开走
余生分开走 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:00

    The success function doesn't execute immediately, but only after the HTTP-response arrives. Therefore, array is still undefined at this point. If you want to perform operations on the HTTP-response data, do it from within the success function, or alternatively, define that operation inside of a function and then invoke that function from within the success callback.

提交回复
热议问题