After hours ploughing through all the posts on this I'm still without a solution. I've got at least 6 divs in a single HTML file which I need to load to a master HTML file. The contents of each div
are posted to different div
containers in the master file. I can get this to work with the code below, but I'm carrying out 6 separate loads of the same file which is clearly resource and time-wasting. I've tried separating ID's with commas on a single line, but I get strange results where data gets posted to the wrong containers. Does anyone know how to achieve a single load?
$(function() {
$("#CountryList").load("https://URL #CountryStore");
$("#YearList").load("https://URL #YearStore");
$("#ProductList").load("https://URL #ProductStore");
});
Make only one request using $.get()
and parse the response yourself and place the various parts where you want them
$.get('https://URL', function(data){
var $data= $(data);
$( "#CountryList" ).html($data.find('#CountryStore'));
$("#YearList").html($data.find("#YearStore"));
$("#ProductList").html($data.find("#ProductStore"));
});
This is essentially what load()
is doing internally
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.