Timestamp AJAX URL

9.2k Views Asked by At

Below is the code I'm using for jQuery BBQ.

$(function(){

var cache = {
    '': $('.content')
};

$(window).bind( 'hashchange', function(e) {
    var url = $.param.fragment();

    $( '.contentarea' ).children( ':visible' ).hide();
    if ( cache[ url ] ) {
        cache[ url ].show();
    } else {
        $( '.content-loading' ).show();
        cache[ url ] = $( '<div class="pageURL"/>' )
        .appendTo( '.contentarea' )
        .load( url, function(){
            $( '.content-loading' ).hide();
        });
    }
    $('#wrapper').scrollTop(0);
})

$(window).trigger( 'hashchange' );

});

</script>

I need to amend the code so that the URL is timestamped. I tried using the following code, but when I did the whole page stopped working:

var url = $.param.fragment()+str;
var date = new Date();
var timestamp = date.getTime();
url=url+'&time='+timestamp;

Any help would be appreciated.

1

There are 1 best solutions below

2
On

The character & is used for the second value pairs. For the first instance, use ? as such:

url=url+'?time='+timestamp;

Also, if ever using & in URL you may need to use the escaped version &amp;