I have implemented some basic ajax for loading pages via an onclick
of the <a>
tag.
The problem is that my JS is not returning to the onclick
its bool
val, here is my JS/jQuery and my HTML, I am sure it is a small oversight on my behalf but its driving me nuts.
JS:
function loadPage (caller) {
var href = $(caller).attr('href');
var url = 'http://localhost/api';
$.ajax({
type: 'POST',
url: url + href,
dataType: 'json',
data: {},
success: function (data) {
$('li.active').removeClass('active');
$(caller).parent().addClass('active');
$('div#content').html(data);
history.pushState({foo: "bar"} , '', href);
return false;
},
error: function () {
return true;
}
});
}
HTML:
<li><a class="header-text" href="/" onclick="return loadPage(this);"></a></li>
In case anyone is wondering I am doing this so that the button will ajax the content, and if the js fails for some reason it will instead load the page fully.