weixin_33682790 2014-04-24 21:43 采纳率: 0%
浏览 13

Ajax负载-多个容器

I am reading about jquery load method. I do not know if there is a way to load two different parts of the response in two different containers, using just a single ajax call, something like:

$( "#b" ).load( "article.html #targetInB" );
$( "#a" ).load( "article.html #targetInA" );

but using a single ajax call.

Thanks in advance.

  • 写回答

1条回答 默认 最新

  • weixin_33695450 2014-04-24 22:08
    关注

    I don't think it's built-in. However, you can load the entire contents into a hidden element temporarily, then move it from there to the target elements. This will reduce the number of AJAX calls to 1:

    $('#temp').load("article.html", function() {
      $('#a').append($('#temp #targetInA'));
      $('#b').append($('#temp #targetInB'));
    });
    

    Here I am using the optional callback ability of .load to do post-processing after the result is returned from the AJAX call. The #temp div gets the entire contents from the AJAX. Then each individual piece is appended to the respective div.

    Demonstration: http://jsfiddle.net/j4DKC/

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分