Results 1 to 4 of 4

Thread: jquery Content?

  1. #1
    Join Date
    Jun 2008
    Location
    England, On a beach somewhere
    Posts
    2,483
    Tokens
    691

    Latest Awards:

    Default jquery Content?

    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;

    http://www.michaeldylanedwards.co.uk...sarticlenumber

    Anyone know the script.
    Sorry about the grammar

  2. #2
    Join Date
    Jun 2008
    Location
    United Kingdom
    Posts
    2,015
    Tokens
    568

    Latest Awards:

    Default

    Check out pushState and location.hash, stackoverflow has some great posts about the advantages of each method and compatibility and whatnot.

  3. #3
    Join Date
    Jun 2008
    Location
    England, On a beach somewhere
    Posts
    2,483
    Tokens
    691

    Latest Awards:

    Default

    Yeah pushState is exactly what I need, although, I can't exactly find the code to put it on my site.

  4. #4
    Join Date
    Jun 2008
    Location
    England, On a beach somewhere
    Posts
    2,483
    Tokens
    691

    Latest Awards:

    Default

    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


    Code:
    <!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


    Code:
    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


    Code:
    <?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...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •