title: AJAX/Jquery/PHP - Load page dependant on anchor/hash tag
body: <p>I have the following code which works great:-</p>
  
  <pre><code>$('.ajax a').click(function() {
      getpageajax(this.href);
      return false;
  });
  
  function getpageajax(getpage) {
      if(getpage == "") {
          //SET ERROR?
          document.getElementById("main").innerHTML = "";
          return;
      }
      if(window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
          xmlhttp = new XMLHttpRequest();
      } else {// code for IE6, IE5
          xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
      xmlhttp.onreadystatechange = function() {
          if(xmlhttp.readyState == 4 &amp;&amp; xmlhttp.status == 200) {
              document.getElementById("main").innerHTML = xmlhttp.responseText;
          }
      }
      var urlarray = getpage.split('/');
      location.hash = urlarray[urlarray.length-1];
      xmlhttp.open("GET", "includes/AJAXgetpage.php?getpage=" + getpage, true);
      xmlhttp.send();
  };
  </code></pre>
  
  <p>Only problem is that I have no idea how to get then read the anchor links I create (e.g. #contact-us) to create bookmarkable pages.</p>
  
  <p>I tried to do a solution based around the following but it seems less than ideal</p>
  
  <pre><code>&lt;script&gt;
  var query = location.href.split('#');
  document.cookies = 'anchor=' + query[1];
  &lt;?php if (!$_COOKIE['anchor']) : ?&gt;
  window.location.reload();
  &lt;?php endif; ?&gt;
  &lt;?php
  echo $_COOKIE['anchor'];
  ?&gt;
  </code></pre>