JS问题:这个变量分明已经指定,为什么alert提示没有定义?谢谢
$.ajax({url:url,type:"POST",contentType:"application/json;utf-8",dataType:'json',cach...
$.ajax({
url: url,
type: "POST",
contentType: "application/json;utf-8",
dataType: 'json',
cache: false,
beforeSend:function(){
$("#content").html("正在请求数据,请稍后...");
},
success: function(data) {
//处理json
d=JSON.stringify(data);
},
error: function(data) {
alert(data);
}
});
alert(d); 展开
url: url,
type: "POST",
contentType: "application/json;utf-8",
dataType: 'json',
cache: false,
beforeSend:function(){
$("#content").html("正在请求数据,请稍后...");
},
success: function(data) {
//处理json
d=JSON.stringify(data);
},
error: function(data) {
alert(data);
}
});
alert(d); 展开
3个回答
展开全部
ajax是异步执行,当alert(d)时,d还不存在,只有当ajax回调完成执行success时候才存在,可以添加async:false测试出来
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
hey ,man!
are you sure it was night??
it is noon ,ok?
about the question !i agree with the advice downstairs!
are you sure it was night??
it is noon ,ok?
about the question !i agree with the advice downstairs!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Hello guys, you must know that ajax is an Object with inner functions, so if you alert below it, it must be null or undefined!
Goodnight !
追问
I should now how to do. .Thinks..
追答
I thought you can define d above it all, and then you use d into success function, if success, then d will be well
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询