steveosoule
10/14/2013 - 5:59 PM

Basic PJAX

Basic PJAX

$(function(){
	var replacePage = function(url) {
		$.ajax({
			url: url,
			type: 'get',
			dataType: 'html',
			success: function(data){
				var dom = $(data);
				var title = dom.filter('title').text();
				var html = dom.filter('.container').html();
				$('title').text(title);
				$('.container').html(html);
			}
		});
	};

	$('a').live('click', function(e){
		e.preventDefault();
		//history.pushState(null, null, this.href);
		replacePage(this.href);
	});

	$(window).bind('popstate', function(){
		replacePage(location.pathname);
	});
});