jquery address how do you use it?

前端 未结 4 1951
盖世英雄少女心
盖世英雄少女心 2021-02-04 05:41

I\'m trying to understand how to use the jQuery address plugin for handling deep linking with ajax.

But the documentation is very poor and I cant find any good tutorials

4条回答
  •  天涯浪人
    2021-02-04 06:00

    A quick tut.: The biggest caveat of using AJAX is that the URL is not changing hence back button is not working + links are not crawled. The workaround for this is to use the page section anchor in the URL, the # sign. Based on the data after the hashsign you can use AJAX, load crawlable pageparts, etc.

    The only problem with this that most browsers do not have an URL change event, based on which, the AJAX content can be loaded, so practicly what the plugin is doing is that from time to time it monitors the URL and if it changed, triggers an event based on tha after-hash-sign-parameters. So basically what you do here is

        $('a').click(function() {  
        **//change the after-hash-sign-params to the value of the clicked link**
            $.address.value($(this).attr('href'));
    
        });
        $.address.change(function(event) { 
     **//define an event handler based on the params...**
             if (event.value = 'sortbyname')
                sortstuffbyname()
    else if (event.value ='sortbysomethingelse')
             sortstuffbysomethingelse();
            // do something depending on the event.value property, e.g.  
            // $('#content').load(event.value + '.xml');  
        });  
    

    I never tried the other plugin but working principles are probably the same.

提交回复
热议问题