function getguid判断用户登录则返回1,没有登录返回0。如果获得1,则执行另外3个函数,但是实际情况,在返回1的时候,另外3个函数并没有执行,试了很多种办法,就没有找出原因在哪里?求助!!
function checkauthor()
{
var topic_id={topicid};
$.ajax({
url: "url",
cache: false,
data:{
'topic_id':topic_id
},
type : 'POST',
success:function(result)
{
console.log(result);
if(result!=1)
{
$('#author').html(result);
}
}
});
}
function getlikes()
{
var topic_id={topicid};
$.ajax({
url: "url",
data:{
'topic_id':topic_id
},
type : 'POST',
cache: false,
success:function(data)
{
console.log(data);
$('#likes').html(data);
}
});
}
function getguid()
{
$.ajax({
url: "url",
type : 'POST',
success:function(data)
{
if(data==1){
window.g_uid=data;
getlikes();
checkLogin();
checkauthor();
}
}
});
}
getguid();
//登录后评论
function afterlogin()
{
var topic_id={topicid};
$.ajax({
url: "url",
cache: false,
data:{
'topic_id':topic_id
},
type : 'POST',
success:function(result)
{
console.log(result);
if(result!=1)
{
$('#after_login').html(result);
}
}
});
}
topicid是后台输出的变量吧。是不是应该var topic_id="{{topicid}}";
你要学会调试程序,看看getguid函数是否执行了,success是否执行了,data的值是否正解
function getguid()
{
console.log("getguid函数执行了");
$.ajax({
url: "url",
type : 'POST',
success:function(data)
{
console.log("success执行了,data是"+data);
if(data==1){
window.g_uid=data;
getlikes();
checkLogin();
checkauthor();
}
}
});
}
每个ajax里面加上
async: false
否则你的ajax是异步执行的,下面的代码已经执行了,但是success却没有执行到。