Best Performance + jQuery Ajax + Div Refresh

后端 未结 4 2040
甜味超标
甜味超标 2021-01-16 13:50

Does anyone have good suggestion of the best option for jQuery Ajax to refresh a DIV?

Following are what I\'m trying to achieve:

  1. Optimization of perfor
4条回答
  •  深忆病人
    2021-01-16 14:53

    With an ajax call the majority of your overhead is going to come from the XHR request itself. Though you can cache your necessary objects in variables to increase performance as much as possible. Assuming your HTML is like this:

    
    
    

    You could then use the following JS

    $(document).ready(function() {
        // Load our DOM objects into vars
        links = $('#nav a');
        contentPane = $('#contentpane');
    
        // On click load content into pane using ajax
        links.click(function(e){
            contentPane.load( $(this).attr('href') );
            e.preventDefault();
        });
    });
    

提交回复
热议问题