简体   繁体   English

单个 .load() 的多个 div

[英]multiple divs with a single .load()

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.我在一个 HTML 文件中至少有 6 个 div,我需要将其加载到主 HTML 文件中。 The contents of each div are posted to different div containers in the master file.每个div的内容都发布到主文件中的不同div容器中。 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.我可以使用下面的代码来使用它,但是我正在对同一文件进行 6 次单独的加载,这显然是浪费资源和时间。 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.我试过在一行上用逗号分隔 ID,但我得到了奇怪的结果,其中数据被发布到错误的容器。 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()发出一个请求并自己解析响应并将各个部分放在您想要的位置

$.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这本质上是load()在内部所做的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM