Ajax中的async

来源:互联网 发布:sqlserver 教程 编辑:程序博客网 时间:2024/06/05 17:46
var temp;
$.ajax({
async: false,
type : "POST",
url : defaultPostData.url,
dataType : 'json',
success : function(data) {
temp=data;
}
});
alert(temp);
 
async的默认设置为true,所有请求均为异步请求。若要将其设置为false,则所有的请求均为同步请求,在没有返回值之前,alert(temp)是不会执行的。
注意,同步请求将锁住浏览器,用户其它操作必须等待请求完成才可以执行。
原创粉丝点击