Having real difficulty implementing this code into my current AJAX script. My AJAX pulls content from an external .html file (content.html) and loads it into a target div onto a number of pages of mine. The hashexchange plugin is a way to implement a pageshow event (i believe) so that the website can be hotlinked and all back/refresh capability can be used regarding the content loaded into my target div.
My ORIGINAL code before adding the pageshow event lines was:
$(document).ready(function(){
$(document).on('click', '#about2', function() {
$("#content").load("content.html #about", function() {
$.getScript("slides.js", function() {
$(window).scrollTop(0);
});
});
});
$(document).on('click', '#process2', function() {
$("#content").load("content.html #process", function() {
$(window).scrollTop(0);
});
});
$(document).on('click', '#materials2', function() {
$("#content").load("content.html #materials", function() {
$(window).scrollTop(0);
});
});
$(document).on('click', '#pricing2', function() {
$("#content").load("content.html #pricing", function() {
$.getScript("tabbedcontent.js", function() {
$(window).scrollTop(0);
});
});
});
This worked fine in terms of the .load function, it even worked in terms of adding an anchor to the web address after clicking the link (i.e: http://crookedcartoon.co.uk/print.html#process) however, these anchors are not hotlinkable, refreshable or are usable with any browser functions. So i updated my code to encompass a bit of what the Ben Alman plugin uses:
$(document).ready(function(){
$(document).on('click', '#about2',function ParseURL() {
switch(location.hash.split("&")[0]) {
case '#about':
$("#content").load("content.html #about", function() {
$(window).scrollTop(0);
});
break;
$(document).on('click', '#process2',function ParseURL() {
switch(location.hash.split("&")[0]) {
case '#process':
$("#content").load("content.html #process", function() {
$(window).scrollTop(0);
});
break;
$(document).on('click', '#materials2',function ParseURL() {
switch(location.hash.split("&")[0]) {
case '#process':
$("#content").load("content.html #materials", function() {
$(window).scrollTop(0);
});
break;
$(document).on('click', '#pricing2',function ParseURL() {
switch(location.hash.split("&")[0]) {
case '#process':
$("#content").load("content.html #pricing", function() {
$(window).scrollTop(0);
});
break;
default:
}
}
$(window).bind("pageshow", function(event) {
if (event.originalEvent.persisted) {
ParseURL();
}
});
$(document).ready(function ($) {
ParseURL();
});
It still doesn’t work, and the original AJAX function no longer works either, can anyone see where im going wrong? My site is www.crookedcartoon.co.uk/print.html
Thanks in advance!