Home > Article > Web Front-end > Reasons and solutions why ajax internal values cannot be called externally
Below I will bring you an article on the reasons and solutions for why ajax internal values cannot be called externally. Let me share it with you now and give it as a reference for everyone.
The reason why the internal value of ajax cannot be called externally and the solution
var id=‘123'; $.ajax({ url:'http://www.xxx.com/ajax', type:'post', dataType: "json", data:{wurl:w_url,murl:m_url}, async : turn, error:function(){ }, success:function(data){ var id= data[‘id']; console.log(id) // 这里出来的是100 } }) console.log(id); //这里出来的是123
The problem lies in the async synchronization step option of ajax. If async: false, means running in synchronous mode, and then execute the following statement after ajax loading is completed. If async: turn, it means asynchronous execution. If ajax does not reach the value, it will have the opportunity to receive the next statement of ajax.
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
Comprehensive analysis of Ajax comprehensive applications
How to use Nginx reverse proxy to avoid ajax cross-domain requests
In-depth analysis of Nginx implementation of AJAX cross-domain request issues
The above is the detailed content of Reasons and solutions why ajax internal values cannot be called externally. For more information, please follow other related articles on the PHP Chinese website!