Hi guys first time posting and total Ajax noob.
Just wondering if anyone can point out where I've gone terribly wrong, appreciate all the help i can get
//Jquery to handle ajax loading links
//Function to handle back and forward
var pooped = ('state' in window.history && window.history.state !== null),
initialURL = location.href;
//function to handle the scenarios where back and forward buttons used in browser
$(window).bind("popstate", function (e) {
// Ignore inital popstate that some browsers fire on page load
var initialPoop = !pooped && location.href == initialURL;
pooped = true;
if (initialPoop) {
return;
}
ajaxLinkPage(location.href);
});
// Ajax Link function
var ajaxLinkPage = function (linkurl) {
console.log(linkurl);
$.ajax({
type: 'GET',
url: linkurl,
data: {},
complete: function (data) {
$('#body_wrap').html($("#body_wrap", data.responseText).html());
history.pushState({
page: linkurl
}, linkurl, linkurl);
}
});
};
// Below this is the Ajax Trigger
$("#nav ul li a").click(function(){
var linkurl = $("#nav ul li a").attr("href");
ajaxLinkPage(linkurl);
$('#dvLoading').css('display','block');
});
The ajax call doesn't work if i put event.preventDefault for the .click()
Works in chrome on some pages but doesn't work at all in safari.
Thanks!
Are you preventing default like this? It should work like so. If not can you post console errors if any?
$("#nav ul li a").click(function(e){
e.preventDefault();
var linkurl = $("#nav ul li a").attr("href");
ajaxLinkPage(linkurl);
$('#dvLoading').css('display','block');
});