Using jQuery load with promises

后端 未结 5 540
夕颜
夕颜 2020-12-09 03:49

I\'m still trying to wrap my head around deferred and what not, so with this in mind I have a question on how to do the following.

My team and I have 3 separate

5条回答
  •  情话喂你
    2020-12-09 04:20

    I use next code for this case:

    $.when(
        $.get('templates/navbar.tmpl.html', function(data) {
            $('#navbar').html(data);
        }),
        $.get('templates/footer.tmpl.html', function(data) {
            $('#footer').html(data);
        }),
        $.Deferred(function(deferred) {
            $(deferred.resolve);
        })
    ).done(function() {
        $.getScript("js/tools/jquery.min.js");
    });
    

    To my mind it looks more structured and pretty nice than previous implementations.

提交回复
热议问题