开发者

Using hash characters in 'pretty urls'

开发者 https://www.devze.com 2022-12-19 19:12 出处:网络
I haven\'t found a good resource in using # in urls to enable bookmarking with ajax calls so I have a few questions.

I haven't found a good resource in using # in urls to enable bookmarking with ajax calls so I have a few questions.

We have a site based on CakePHP using 'pretty' urls essentially www.mysite.com/c开发者_如何学Goontroller/action/param1:param2 I noticed that Facebook uses a weird syntax with their pretty urls ex) #!/?ref=logo

Is there a way we can use # marks to enable bookmarking this way keeping our 'pretty' urls?

Thanks


Only if you use Javascript to redirect to the correct URL.

PHP, and any other server-based platform does not have access to the data after the hash mark, and therefore is only for use in Javascript and other client-side languages.

You could put some Javascript code to correctly load a page via AJAX based on the tag. However, it is probably not of much value unless your website is a complete application. AKA, most of the stuff that happens doesn't require a refresh.

An example of this would be (in jQuery):

$('a').click(function(){
    var page_url = $(this).attr('src');

    // Set the hash and load the page into the main container
    location.hash = page_url;
    someLibrary.load(page_url);
});
0

精彩评论

暂无评论...
验证码 换一张
取 消