ajax调用超链接和hashbang

时间:2013-12-03 08:10:19

标签: jquery ajax hash

我尝试在超链接点击的分页中使用ajax调用,但如果我使用以下方法则会失败

$('a#page').on('click',function(event){      
    var page = $(this).data('id');     
    //here I generate my own url
    window.location.hash = buildURI('start', page);
    search_products();

});

第一次点击正在执行,第二次点击失败,并在firebug中出现以下错误

syntax error
this.href=

BuilURI方法

//Method to build hashbang
function buildURI(facet, values) {
    var uri_params = ['price', 'display', 'ram', 'hdd', 'brands', 'model', 'cpu', 'category','start','search_selection','order'];
    //console.log(values);
    var url = getUrlVars();   
    if (facet === 'brands') {
        get_models(values);
    }

    if(values.legth === -1){
        delete url.facet;
    }

    if (window.location.hash+'!') {
        var hash = window.location.hash;
        if(facet === "brands"){
            if(url.model){
                delete url.model;
            }
        }

    if(facet != "start"){
            if(url.start){
                delete url.start;
            }
        }        
        //check hashabng against parameters
        $.each(uri_params, function(index, param) {
            $.map(url, function(value, key) {
                if (key === facet) {
                    url[key] = values;
                }
            });
        });

        var uri = '#!' + decodeURIComponent($.param(url, true));
        //if facet do not match with the hashbang string we append a new one
        if (!hash.match(new RegExp('!' + facet + '(.*)|&' + facet + '(.*)'))) {
            uri += "&" + facet + "=" + values;
        }
    } else {
        uri += '#!' + facet + "=" + values;
    }

    return uri;
}

0 个答案:

没有答案