I run in to a problem whan i do somthing like this
var abc = false;
function doSomthing(){
abc = true;
return abc;
}
and it returns false, but if i run the function twice (in console), the second time returns true.
Thanks
the orignal function
var session_id_resualt = false;
function islogdin() {
if (localStorage.email == undefined) {
localStorage.email = "";
}
if (localStorage.session_id == undefined) {
localStorage.session_id = "";
}
$.post(server + "loginCheck.php", {
loginCheck: "",
cookie: readCookie("h"),
session_id: localStorage.session_id,
email: localStorage.email
},
function (json) {
json = $.parseJSON(json);
if (json.logdin) {
if (json.logdin == "1") {
//var s_id = json.session_id;
session_id_resualt = json.session_id;
//return s_id;
} else {
session_id_resualt = false;
// return false;
}
} else {
session_id_resualt = false;
// return false;
}
});
return session_id_resualt;
}
$.postis asynchronous. You’ll need to wait for the result. However, since$.postdoens’t provide a simple way to change the$.ajaxsettings you’ll have to use$.ajaxinstead withasync: false:References: