I created a function to return true
or false
when ajax. At the beginning of the function I declare a variable "r" to receive true
in case of success or false
in case of failure, but the variable does not have its value modified. and ends up returning the value that was assigned at start false
. What's wrong?
function loadSkeleton(r) {
var r;
$.ajax({
method: "POST",
url: "/sys/ajax/publicacao.xhtml"
}).done(function (answer) {
$('head').append('<link rel="stylesheet" type="text/css" href="/css/post.css">');
$('head').append('<link rel="stylesheet" type="text/css" href="/css/aside-publication.css">');
$('head').append('<script type="text/javascript" src="/scripts/js/other-publi.js"></script>');
setTimeout(function () {
$('.side-left').html($(answer).find('content').html());
}, 2000);
r = true;
}).fail(function (jqXHR, textStatus) {
$('.side-left').html('<p>Failed request</p>');
r = false;
});
return r;
}
.done
is working because DOM changes are visible.