Smccullough
Smccullough

Reputation: 363

Multiple JSON objects

Hoping someone can answer this one... Is it possible to load multiple JSON files using a single jQuery.ajax(); call? or would I need to create a call for each file?

Your friendly neighbourhood, Smccullough

Upvotes: 2

Views: 1324

Answers (2)

Adam Peter Nielsen
Adam Peter Nielsen

Reputation: 273

jQuery.ajax() does one http request at a time.

You could wrap it in a jquery function for loading the files. Pseudo-ish code:

jquery.fn = function loadFiles(data){
  $.ajax({
    url: data.file,
    dataType: 'json',
    success: callback
    ... and so on
  });

}

somewhere else in your code:

$(this).loadFiles({file:'file-one.ext'});
$(this).loadFiles({file:'file-two.ext'});

Upvotes: 1

polarblau
polarblau

Reputation: 17734

I believe you'll have to make multiple calls or concatenate the files at the server.

Upvotes: 4

Related Questions