How do i load multiple html files and putting them into a specified html element?
I tried with no changes:
$('#asd').load('file.html,pippo.html');
you could get multiple items and add them to the element.
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
data1
and data2
are deferred objects, not text/html. Your code as posted will append the string [object Object][object Object]
to .result
async:false
locks the browser during the requests and results in the requests being sent out sequentially rather simultaneously, possibly causing it to take longer to get all of the requested html (causing the previously mentioned lock to last longer).
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);
});