pbojinov
2/19/2014 - 8:46 PM

Multiple Simultaneous Ajax Requests (with one callback) in jQuery

Multiple Simultaneous Ajax Requests (with one callback) in jQuery

// http://css-tricks.com/multiple-simultaneous-ajax-requests-one-callback-jquery/?utm_source=javascriptweekly&utm_medium=email

$.when(
  // Get the HTML
  $.get("/feature/", function(html) {
    globalStore.html = html;
  }),

  // Get the CSS
  $.get("/assets/feature.css", function(css) {
    globalStore.css = css;
  }),

  // Get the JS
  $.getScript("/assets/feature.js")

).then(function() {
  // All is ready now, so...
  //globalstore.css
  //globalstore.html
});