javascript - jQuery execute script after everything ready -
i using ajax in webpage , have javascript in ajax page executed when ajax page load. problem is, how can have jquery execute script after ajax page loaded?
i have tried with:
$( '#ajaxdiv' ).load(function() { }
but didn't run code @ all. if put .ready()
, run code, not after loaded.
is possible have piece of code executed after ready?
you should in deferred promise object. decent article explaining / how use it.
deferred object http://api.jquery.com/category/deferred-object/
http://css-tricks.com/multiple-simultaneous-ajax-requests-one-callback-jquery/ (sample code article below. )
$.when( // html $.get("/feature/", function(html) { globalstore.html = html; }), // css $.get("/assets/feature.css", function(css) { globalstore.css = css; }), // js $.getscript("/assets/feature.js") ).then(function() { // ready now, so... // add css page $("<style />").html(globalstore.css).appendto("head"); // add html page $("body").append(globalstore.html); });
Comments
Post a Comment