Because AJAX is executed asynchronously by default, that is, the next line of JS statement is executed without waiting for the request to finish, resulting in null assignment.
Solution:
Add the following code:
$.ajax({
async:false,
//******other codes
});
It can be solved.
Read More:
- The solution of calling$. Ajax successfully but the success method does not respond
- If the request parameter is formdata, use the Ajax operation
- [Solved] it only responds to error and does not enter success after AJAX is successfully processed
- Difference between contenttype and datatype in Ajax request of jquery
- [Solved] ajax Error: Uncaught SyntaxError: Unexpected end of JSON input
- How to download files by post submission under Ajax
- [Solved] Error: Incorrect arguments to mysqld_stmt_execute
- Failed to execute ‘setRequestHeader’ on ‘XMLHttpRequest’: String contains non ISO-8859-1 code point.
- Using ts-node to Execute .ts files Error [Solved]
- [Solved] Failed to execute ‘getRangeAt‘ on ‘Selection‘: 0 is not a valid index.“
- [Solved] Uncaught DOMException: Failed to execute ‘readAsDataURL‘ on ‘FileReader‘: The object is already busy
- SVN Update Error: Please execute the ‘Cleanup‘ command.
- Vue Error: renren-fast-vue execute npm install Error [How to Solve]
- The solution to the failure of HTML introducing external JS
- Solution to some map files in JS folder after Vue packaging (remove the map. JS file)
- Vue elementui: solution for error: avoided redundant navigation to current location: “/xxx”
- [Vue error] the solution to the template root requires exactly one element error reporting
- The solution to the problem that the custom styles of UI components such as element-ui in the vue project do not take effect
- Solution to build error in Vue project (error in static/JS)/vendor.xxxxx.js from UglifyJs)