Home > Article > Web Front-end > A brief analysis of the reasons why global variables cannot be assigned values in jquery ajax asynchronous calling methods and their solutions_jquery
When calling a jquery ajax method, we sometimes need the method to return a value or assign a value to a global variable, but we find that the value we want is not obtained after the program is executed. This is very likely It’s because you are using ajax’s asynchronous call async:true (default), such as:
Another solution is to write your code directly into the success method. (Depending on your business, not everything can be written directly into success).
Note: If set to async: false, the advantages of ajax asynchronousness will be lost.