0

I try to use ajax calls in my pagination on hyperlink click, but fails if I use the following method

$('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();

});

the first click is getting executed and the second fails with the following error in firebug

syntax error
this.href=

BuilURI method

//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;
}
fefe
  • 8,755
  • 27
  • 104
  • 180
  • Show us `buildURI()`. Where is Ajax call in this? No one would be able to help you with this code as it seems OK to me. Probably there would be some error in the part that you are not showing us. – Kamran Ahmed Dec 03 '13 at 08:13
  • I added my method as well – fefe Dec 03 '13 at 08:19
  • I am not vry sure how u using hash and ajax together but this thread may help u.. [link] (http://stackoverflow.com/questions/3870057/how-can-i-update-window-location-hash-without-jumping-the-document) – Neha Dec 03 '13 at 08:56

0 Answers0