Ajax assigns a global variable to a value problem
Today, when I was doing the project, I encountered a problem. I am using Ajax, in $.ajax ({Inside to give a global variable assignment, the result is no value, tangled long time, later on-line check, just know, AJAX default is asynchronous request, (when to assign value, at this time the value is not received, so the assignment is not successful) if you want to $.ajax ({ The value of the global variable is assigned, it needs to be changed to synchronous operation, that is, add async:false.
$.ajax ({
Type: "Post",
URL: "A.action",
Data: {},
DataType: ' Text ',
async:false,//is set to synchronous operation to assign a value to the global variable successfully
Success:function (data) {
Usersname = Data;//usersname As the previously declared global variable
}
});
Ajax assigns a global variable to a value problem