jquery地址插件问题

时间:2015-06-04 14:59:30

标签: javascript jquery ajax

我正在使用jquery地址插件,我在列表页面上实现了插件,当我点击其中一个链接时,该函数将使用ajax拉取数据并获取内容并覆盖当前列表html,这页面有'后退'按钮,我使用window.history.back()返回列表页面,这个工作正常,直到这一点,但之后再次点击其中一个链接时,jq地址行为是丢失 。

open_ajax函数用于拉取数据并插入paginatedContent html div

$(document).ready(function(){
    refreshjQAddress();
});

function refreshjQAddress(){
    mainPath = "";

    if($('.jqaddress').length > 0){
        $.address.init(function(event) {
            $('.jqaddress').address(function() {

                return $(this).attr('href');
            });
        }).internalChange('change', function(event) {
            path = event.value;

            var ran=Math.random();

            urlPath = path;
            console.log(urlPath);

            alert(urlPath);
            open_ajax(urlPath);
            mainPath = urlPath;
        }).externalChange(function(event) {
            var windowLoc = window.location+"";

            hashIndex = windowLoc.indexOf("#");

            if(hashIndex > 0){
                newLoc = windowLoc.substring(hashIndex+1);
                mainLoc = windowLoc.substring(0,hashIndex);
                if(mainLoc.indexOf("http://") > -1){
                    mainLoc = mainLoc.replace("http://","");

                    indexOf = mainLoc.indexOf("/");
                    mainLoc = mainLoc.substring(indexOf);
                }

                mainPath = mainLoc;
                windowLoc = newLoc;
            }

            if(mainPath == ""){
                mainPath = windowLoc;
            }

            if(windowLoc != mainPath){    
                var ran=Math.random();

                open_ajax(windowLoc);               
            }
        }).history(true);
    }
}

var oldData;
function open_ajax(path){   
    var ran=Math.random();

    if(path.indexOf("?") > 0){
        urlPath=path+'&'+ran;
    }else{
        urlPath=path+'?'+ran;
    }

    oldData = $('#paginatedContent').html();

    $.ajax({
        url: path,
        async: false,
        beforeSend:function(data){          
            $('#paginatedContent').html("<div class='loaderDiv'><img src='/img/ajax-loader.gif' alt='' /></div>");

        },
        success: function(data) {
            $('#paginatedContent').html("<div class='ajaxDataDiv' style='display:block'>"+data+"</div>");

            if($("#hidden_meta_title").length > 0){
                document.title = $("#hidden_meta_title").html();
            }

            $(".relatedBannersAlbums").show();
        }
    });
}


function back_btn(){
        window.history.back();
}

0 个答案:

没有答案