ajax同步

ajax一版写法是异步的,同步写法可以用async属性,false同步。true是异步

console.log(1) 

$.ajax({
type : 'GET',
url : 'http://wthrcdn.etouch.cn/weather_mini?city=上海',
async: false,
success: function (data) {
console.log(2)
}
});

console.log(3)

控制台会一次打印出1,2,3

如果async: true,会打印出1,3,2

目前只研究到ajax,axios有没有这个属性还不清楚,后续研究出会后面更新的。

原文地址:https://www.cnblogs.com/yck123/p/10175387.html