jQuery的链接.load()请求? [英] jQuery chaining .load() requests?

查看:123
本文介绍了jQuery的链接.load()请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我正在与jQuery的 .load()刚才和它看起来我们可以'牛逼配置 $(#示例)的负载('./ uri.ext #ID')来链为这样的:

So I was working with jQuery's .load() just now and it looks like we can't configure $("#example").load('./uri.ext #ID') to chain as such:

$(#示例)。负载(./ uri.ext#ID1)。负载(./ uri.ext#ID2)。负载(./ URI。分机#ID3')

如果我们有资料核实或东西来动态地构建一个页面,而不是存储在一个字符串变量或沿着这些线路的东西的HTML模板文件,该文件当然是有用的......再加上,我们可以保持几个这样的一个文件。

Which of course would be useful if we had a template file of DIVs or something to dynamically build a page and not store the HTML in a string variable or something along those lines... plus, we could keep several of these in one file.

在理想情况下,我想窝事情本身与命令:

Ideally I would like to nest things as such with that command:

<div id="example">
    <div id="ID1">
        <div id="ID2">
            <div id="ID3">
            </div>
        </div>
    </div>
</div>

我收到的问题是双重的。首先,异步:请求真正属性将导致下一个请求火和安排不preform如预期。我再试图运行嵌套的$(#示例)。负载(./ uri.ext#ID1)。ajaxCompletes(函数(){/ 下一个.load()的顺序的/ })`这结束了在未结束递归陷阱,不断发出对这些文件的请求。

The problems I'm getting are two-fold. First, the async : true property of the request causes the next request to fire and the placement doesn't preform as intended. I had then attempted to run nested $("#example").load('./uri.ext #ID1').ajaxCompletes(function () {/next .load() in sequence/})` which ended up in a recursive trap that didn't end and kept sending requests for those files.

这是如何完成我后,我用的语法/方法,就像我曾试图有什么想法?此外,如果这是没有问题的,只是我的jQuery的链接的一部分的误解,解释我将非常感谢任何解释成说。

Any thoughts on how to accomplish what I'm after with a syntax/method like I had attempted? Also, if this isn't a problem and just a misunderstanding on my part of jQuery's chaining, an explanation I would be very thankful for any explanation into that.

推荐答案

您需要嵌套它们在回调函数来实现这一点:

You would need to nest them in the callback functions to achieve this:

$('#example').load('./uri.ext #ID1', function() {
  $('#ID1').load('./uri.ext #ID2', function() {
    $('#ID2').load('./uri.ext #ID3', function() {
      // load successful
    });
  });
});

这篇关于jQuery的链接.load()请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆