Log in

View Full Version : jquery Content?



Mickword
06-07-2015, 10:14 PM
Hey, long time and that.

Been looking for a content script for my website but I really can't find one.
At the moment I'm using Ajax Content for my website, but I've hit a snag because I want the actual news pages of said website to be directly linkable, so instead of being shared from;

www.michaeldylanedwards.co.uk
Where the actual news article I want to share is lost because of Ajax content.

But I want;

www.michaeldylanedwards.co.uk/#/newsarticlenumber

Anyone know the script.
Sorry about the grammar :')

Trinity
07-07-2015, 11:15 AM
Check out pushState and location.hash, stackoverflow has some great posts about the advantages of each method and compatibility and whatnot.

Mickword
07-07-2015, 10:54 PM
Yeah pushState is exactly what I need, although, I can't exactly find the code to put it on my site.

Mickword
08-07-2015, 02:00 AM
Sup, right so I'm using this script from Tutorialzine.
And basically the basic set up for a link is:


/page_number.php


and the link itself is; pagenumber


But I cant link anything other than page_number.php and I need to know how I can change the script so that I can link any link on my site without it messing up.


Here's the code;


index.html



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Title</title>
<link rel="stylesheet" type="text/css" href="demo.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="script.js"></script>


</head>


<body>


<a href="#page1">Page 1</a>
<a href="#page2">Page 2</a>
<a href="#page3">Page 3</a>
<a href="#page4">Page 4</a>




<div id="pageContent">
Hello, this is a demo for a <a href="http://tutorialzine.com/2009/09/simple-ajax-website-jquery/" target="_blank">Tutorialzine tutorial</a>. To test it, click some of the buttons above. Have a nice stay!</div>
</div>



</body>
</html>


script.js



var default_content="";


$(document).ready(function(){

checkURL();
$('ul li a').click(function (e){


checkURL(this.hash);


});

//filling in the default content
default_content = $('#pageContent').html();


setInterval("checkURL()",250);

});


var lasturl="";


function checkURL(hash)
{
if(!hash) hash=window.location.hash;

if(hash != lasturl)
{
lasturl=hash;

// FIX - if we've used the history buttons to return to the homepage,
// fill the pageContent with the default_content

if(hash=="")
$('#pageContent').html(default_content);

else
loadPage(hash);
}
}




function loadPage(url)
{
url=url.replace('#page','');

$('#loading').css('visibility','visible');

$.ajax({
type: "POST",
url: "load_page.php",
data: 'page='+url,
dataType: "html",
success: function(msg){

if(parseInt(msg)!=0)
{
$('#pageContent').html(msg);
$('#loading').css('visibility','hidden');
}
}

});


}


load_page.php



<?php


if(!$_POST['page']) die("0");


$page = (int)$_POST['page'];


if(file_exists('page_'.$page.'.php'))
echo file_get_contents('page_'.$page.'.php');


else echo 'There is no such page!';
?>



Any help will be really appreciated...

Want to hide these adverts? Register an account for free!