标签:style blog color io os ar java sp 数据
本篇文章为小编的备忘录,对一些遇到的各种问题的解决方法进行简单的整理,方便自己查看,大家也可以参考。
var msg='';
$.ajax({
url: 'messageAction.do?reqCode=order',
type: 'post',
data:{
},
dataType: "json",
success:
function (data) {
msg=data.msg;
alert(msg);
}
});
alert(msg);对这个ajax请求,第一个alert可以正确的弹出请求到的数据,但第二个alert却弹出空值,这是因为这个ajax请求为异步的,当执行第二个ajax时ajax请求的数据还未返回,所以无法正确弹出。可以改成下面的形式(同步的)
$.ajax({
url: 'messageAction.do?reqCode=order',
type: 'post',
data:{
},
dataType: "json",
async:false, <span style="font-family: Arial, Helvetica, sans-serif;">//同步</span>
success:
function (data) {
msg=data.msg;
alert(msg);
}
});
标签:style blog color io os ar java sp 数据
原文地址:http://blog.csdn.net/u012116457/article/details/40054699