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.