如何使用Ajax、Javascript添加页码


How to add page number using Ajax, Javascript?

我有一个问题:有一个使用Jquery(Ajax)进行异步页面更改和加载的脚本:

        $('.page_button').live('click',function() {
            $('#ajaxBusy').show();
            $('.selected_page_button').attr('class','page_button');
            $(this).attr('class','selected_page_button');
            $.post("http://"+document.location.host+"/index.php/welcome/update_records_set/"+this.id,
            function(data)
            {
                if (data != "") 
                {
                    $(".records_content:last").empty();
                    $(".records_content").html(data);           
                }
                $('#ajaxBusy').hide();
            });
        });

这段代码有效,但我也需要在不刷新的情况下为URL添加"#page"。此外,我使用CodeIgniter进行开发,一些控制器的这个功能加载了一个页面:

public function language_testing($language_code) {
//some actions
}

但是,如何从"http://some_site/controller/en#5"中提取页码以加载第五页?有标准的方法吗?

如果你想从url中获取哈希值,那么你可以这样做:

var hassh = window.location.hash;
var hashVal = hassh.substr(1, hassh.length);
console.log( hashVal );

如果你想从url得到它,那么:

var url = "http://some_site/controller/en#5".split("#");
console.log( url[1] ); 

你可以设置散列如下:

window.location.hash = "#yourValue";

你是说类似的东西吗