JQuery loads multiple html files into one element

How to upload multiple html files and put them in the specified html element?

I tried without changes:

$('#asd').load('file.html,pippo.html');
+3
source share
2 answers

You can get multiple items and add them to the item.

jQuery.ajaxSetup({ async: false }); //if order matters
$.get("file.htm", '', function (data) { $("#result").append(data); });
$.get("pippo.htm", '', function (data) { $("#result").append(data); });
jQuery.ajaxSetup({ async: true });  //if order matters
+4
source

Try this using deferred objects.

var defArr = [];
defArr.push($.get('file.html'));
defArr.push($.get('pippo.html'));
$.when.apply($,defArr).done(function(response1,response2){
    $('.result').html(response1[2].responseText + response2[2].responseText);
});
+4
source

All Articles