This function returns an undefined value when it is executed. I want it to return true if the page is loaded and false if not:
function JLoad (url) {
var uri = url + ' #div';
$("#div").load(uri, {'bd': '1'}, function(response, status, xhr){
if (status != "error"){
if (window.history && window.history.pushState)
{
window.history.pushState({}, 'Test', url);
}
else
{
window.location.hash='!/'+url;
}
return true;
}else{
return false;
}
});
};
This is part of the code used to request the function:
$(document).ready(function() {
$("a").on("click", function() {
var url = $(this).attr("href").replace('./', '');
console.log(JLoad(url));
return false;
});
});
loadis Asynchronous, you can not return a value from the callback!var uri = url + ' #div'