Ajax将元素加载到页面中

时间:2013-01-07 10:36:58

标签: ajax load

尝试将元素中的内容从另一个页面加载到另一个元素中,问题在于它将整个页面加载到元素中。请在此处查看:http://www.monsterhighshop.co.uk/gadgets-electonics

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

0 个答案:

没有答案