http://fh80.student.eda.kent.ac.uk/fyp/ Live example
If you see this page, select sports / places / athletes, etc., this allows you to view, but all this is called through AJAX.
This works fine, but I have problems with inline links. For instance:
Go to the sport
Go to track and field
Go to the "Hampden Park" link in red
This link does not reload in the AJAX window, it loads it into a new window ...
This is the code that should set the class ajaxLinkto load the AJAX page into the div as much as possible #grid(just like for all other pages).
var newLink = $('.ajaxLink');
newLink.click(function (e) {
$.ajax({
url: newLink.attr('href'),
type: 'POST',
success: function (data) {
$('#grid').remove();
successHandler(data)
}
});
e.preventDefault();
});
Here is the code for AJAX that I am using (it is long):
$(function () {
var ajaxElement = $('#browserMenu a, .ajaxLink');
ajaxElement.on('click', function (e) {
var src = $(this).attr('href');
console.log(src);
var thisEl = $(this);
var runAJAX = (src && src != '#') ? true : false;
if (runAJAX) {
var targetElement = $('#grid');
var parentElement = $('#ajaxParent');
if (src === 'index.html') {
$('#content').load('index.html #inner-content', function () {
$('.selected-menu').each(function () {
$(this).removeClass('selected-menu');
});
thisEl.addClass('selected-menu');
$('#jsCode code pre').load('js/nocomments.js');
});
} else {
$.ajax({
url: src,
dataType: 'html',
statusCode: {
404: function () {
console.log(src + ' - not found');
}
},
cache: false,
error: function (jqXHR, textStatus, errorThrown) {
console.log(errorThrown);
},
success: successHandler
});
}
e.preventDefault();
}
function successHandler(data) {
targetElement.remove();
$('.selected-menu').each(function () {
$(this).removeClass('selected-menu');
});
thisEl.addClass('selected-menu');
var newContent = $('<div id="grid" />');
newContent
.html(data)
.css("opacity", "0");
parentElement.append(newContent);
newContent.animate({
opacity: 1
}, 500);
var newLink = $('.ajaxLink');
newLink.click(function (e) {
$.ajax({
url: newLink.attr('href'),
type: 'POST',
success: function (data) {
$('#grid').remove();
successHandler(data)
}
});
e.preventDefault();
});
}
});
$('#jsCode code pre').load('js/nocomments.js');
});