You should wait on jQuery's AJAX request to complete [and eventually for the data to be appended] before trying to bind the scrollspy
. Make use of the $().load()
callback.
jQuery(function(){
$('#sub-nav').load('subnav.html', function(){
$('body').scrollspy();
});
});