0

试图将一个元素中的内容加载到另一个页面的另一个元素中,问题是在 chrome 中它将整个页面加载到元素中。在这里亲自查看:http ://www.monsterhighshop.co.uk/gadgets-electronics

$(function(){

    e.preventDefault(); 
    /*  
    if uncomment the above line, html5 nonsupported browers won't change the url but will display the ajax content;
    if commented, html5 nonsupported browers will reload the page to the specified link. 
    */

    //get the link location that was clicked
    $("a[rel='sort']").click(function(e){
    pageurl = $(this).attr('href')+"?rel=sort #categoryproducts-productlisting";
    $('#categoryproducts-productlisting').load(pageurl);

    //to change the browser URL to 'pageurl'
    if(pageurl!=window.location){
        window.history.pushState({path:pageurl},'',pageurl);    
    }
    return false;  
});
});

/* the below code is to override back button to get the ajax content without reload*/
$(window).bind('popstate', function() {
$.ajax({url:location.pathname+'?rel=sort',success: function(data){
    $('#categoryproducts-productlisting').html(data);
}});
});
4

0 回答 0