0

我正在使用以下代码用 jquery 加载一些片段

var box = $(this).closest(".product-contain").children(".title:first");
box.load(url + " .maintitle", data);
var box = $(this).closest(".product-contain").children(".detail:first");
box.load(url + " .alldetail", data);

(我不想一次加载整个 .product-contain ,因为其中一部分正在由用户同时编辑)

但它会向服务器发出 2 个相同内容的请求。

我可以通过一个请求以某种方式做到这一点吗?

谢谢!

4

1 回答 1

3

您可以做一个$.get()并自己加载内容,如下所示:

 var pc = $(this).closest(".product-contain");
 $.get(url, data, function(html) {
   var resp = $(html);
   pc.children(".title:first").html(resp.find(".maintitle"));
   pc.children(".detail:first").html(resp.find(".alldetail"));
 });

这可能看起来有点奇怪,但.html()使用 jQuery 对象是.empty().append().

于 2010-10-21T23:46:53.597 回答