Reputation: 367
I have this code
$("body").on({
click: function(event){
event.preventDefault();
var aLink = $(this).attr("href");
$("#content").load(aLink+" #loader", function(){
//Callback here
});
$("#crumbbar").load(aLink+' .breadcrumbs', function(){
//Callback here
});
}
}, "a");
Can this be optimized in such a way that I only have 1 load command?
Upvotes: 1
Views: 3357
Reputation: 318352
To only do the ajax call once, you would have to use another of jQuery's ajax functions, like $.get
, which load()
is a shortcut for:
$(document).on('click', 'a', function(e) {
e.preventDefault();
var aLink = $(this).attr("href");
$.get(aLink, function(data) {
$("#content").html($(data).find('#loader'));
$("#crumbbar").html($(data).find('.breadcrumbs').first())
});
});
Upvotes: 2