2

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.

James Allardice
  • 164,175
  • 21
  • 332
  • 312
CoreyRS
  • 2,227
  • 3
  • 26
  • 44
  • 2
    What error message did it stop working with? – Pekka May 29 '12 at 22:22
  • There wasn't an error message that appeared, but my other jquery functions wouldn't work. It's something to do with this the '+str' in this line var url = $.param.fragment()+str; When taken out the page works again. Not sure if it's actually needed or not. – CoreyRS May 29 '12 at 22:39
  • If you output your url variable in the console, what does it print ? – Marc-Emmanuel Ramage Feb 13 '13 at 09:05

1 Answers1

1

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;

arttronics
  • 9,957
  • 2
  • 26
  • 62
  • Ahhh, cheers. I usually use ? when writing PHP timestamps but the place i got the code i used from said to use & so i tried that. Will test it with ? and see if it works. – CoreyRS May 29 '12 at 22:33
  • I'm not sure about the other markup, just the **url variable**. Hopefully somebody will come along and provide additional solution. You should edit your markup to include this change. Reference SO accepted answer for adding timestamp to URL [here](http://stackoverflow.com/a/5945116/1195891). – arttronics May 29 '12 at 23:34