I have a simple test page I’m using to test out displaying partial views with a vertical tabbed interface and jquery in MVC3…everything works fine, but I have one small issue.
Everything works fine, but I’d like to add a “loading” message and change the
This is my js code:
$('#left-nav li').live('click', function (event) {
var navlink = $(this).children("a").attr("href");
$('#left-nav li').removeClass('active');
$.ajax({
url: navlink,
success: function (data) {
//data contains the result returned by server you can put it in div here
$('.content-panel').html(data);
}
});
$(this).addClass('active');
//here you have to return false to prevent anchor from taking you to other page
return false;
});
Is there a way to intelligently determine if the partial has fully loaded before changing class?
Simply move your logic into the success callback:
I would also recommend switching to
.on()rather than.live(). This requires jQuery 1.7+: