2

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

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

Comments

1

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'});

1 Comment

jQuery provides the getJSON() method for this purpose. No need to wrap ajax() again. — docs.jquery.com/Getjson

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.