Home > front end >  The ajax request data, and how the data assigned to global variables
The ajax request data, and how the data assigned to global variables

Time:01-23

My js code

CodePudding user response:

The so-called global variables, is that there is no other functions or scope of variables,

You can directly in the ajax method returns with the window. The reData=https://bbs.csdn.net/topics/result; This way the assignment,

Can also be defined in the external variables, then the assignment:

Var reData;

Ajax (... , the function (result) {

RecordData=https://bbs.csdn.net/topics/result;
})

CodePudding user response:

Directly in front of the js, define a variable is a global variable, and then gave him the assignment can be in local

CodePudding user response:

Build var to convert into the let, more rigorous, after all version changed,

CodePudding user response:

ぃ reference 2 floor of the white dragon, reply:
directly in front of the js, define a variable is a global variable, and then gave him the assignment can be in local

Met the same problem today, I have to say, this problem has nothing to do with whether defines the global variable before perform ajax, has nothing to do with the var or let more (let change the local scope, using the change will be the local variables) just because the ajax itself is executed asynchronously, lead to the internal definition of any variable external cannot call, in solution for ajax (method at the same level of success, don't write in it) add async: false properties, variable step for synchronization, so that you can make success method defined in the global variables in an ajax calls!
  • Related