1
I created a function to return true
or false
when ajax. At the beginning of the function I declared a "r" variable to receive true
if it succeeds or false
in case of failure, but the variable does not have its modified value. and ends up returning the value that was assigned at the beginning false
. What’s wrong with it?
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;
}
The .done
is working because the changes in the DOM are visible.