Search code examples
phpjqueryhashchange

Can the PHP $_GET be used to get a variable in the URL using Hashchange?


<a href="#create=1">Click Me</a>
<script src="https://raw.github.com/cowboy/jquery-hashchange/v1.3/jquery.ba-          hashchange.js"></script>
<script type="text/javascript">
    $(window).hashchange(function () {
    //
    });
</script>

When Click Me is clicked the URL looks like this "www.mydomain.com/#create=1".

What I am trying to do is us the $_GET in PHP to bring down the parameter. Ex:

<?php echo $_GET['create'];?>

Using the

<a href="?create=1">Click Me</a>

works, but it reloads the page and that is what I am trying to avoid. Any help would be greatly appreciated.


Solution

  • There is a new future for that:

    window.history.pushState("Remember me!", "Changing the get Parameter...", "?create=1");
    

    You can apply this to all links by using this:

    $("a").click(function() {
    
        if ($(this).attr("href").substr(0, 1) != "#") {
            $("body").load($(this).attr("href"));
            window.history.pushState("Remember me!", "Nothing special", $(this).attr("href"));
            return false;
        }
    });