Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting this pushState / load content code working
    primarykey
    data
    text
    <p>I'm trying to get the code I found <strong>here</strong> working on my site. As expected, the site was built as a normal site, sending HTTP requests for page changes, and now i'm trying to upgrade it to full ajax.</p> <p>The code below executes the pushState, and the back/forward buttons work, but I can't get the content of the page to change. Anyone know where I'm going wrong?</p> <pre><code>&lt;script&gt; $(function(){ $('a').on('click', function(e) { $("#loading").show(); href = $(this).attr("href"); loadContent(href); // HISTORY.PUSHSTATE history.pushState('', 'New URL: '+href, href); e.preventDefault(); }); // THIS EVENT MAKES SURE THAT THE BACK/FORWARD BUTTONS WORK AS WELL window.onpopstate = function(event) { $("#loading").show(); console.log("pathname: "+location.pathname); loadContent(location.pathname); }; }); function loadContent(url){ // USES JQUERY TO LOAD THE CONTENT $.getJSON("post.php", {cid: url, format: 'json'}, function(json) { // THIS LOOP PUTS ALL THE CONTENT INTO THE RIGHT PLACES $.each(json, function(key, value){ $('#wrapper').load(href); }); }); } &lt;/script&gt; </code></pre> <p>HTML:</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;title&gt;Title&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;a href="link1.php"&gt;&lt;/a&gt; &lt;a href="link2.php"&gt;&lt;/a&gt; &lt;div id="wrapper-outer"&gt; &lt;div id="wrapper"&gt; &lt;/div&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Edit:</p> <p>Apologies, it seems the link never inserted.</p> <p>Article: <a href="http://www.seomoz.org/blog/create-crawlable-link-friendly-ajax-websites-using-pushstate" rel="nofollow">http://www.seomoz.org/blog/create-crawlable-link-friendly-ajax-websites-using-pushstate</a> Working example: <a href="http://html5.gingerhost.com/" rel="nofollow">http://html5.gingerhost.com/</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload