【问题标题】:jquery.get success function firing early with Hypnotoad and Mojolicious?jquery.get 成功函数提前使用 Hypnotoad 和 Mojolicious 触发?
【发布时间】:2012-10-23 12:00:21
【问题描述】:

关于我在 hypnotoad vs Morbo 中看到的一些行为,我有一个简短的问题。

我有以下一段 jquery 代码,它是在事件中触发的。

alert('calling update device list');

    $.get('updateDeviceList',

            function (data) {

                  alert('In update device list');

                  $("div#devicelist").html(data);

             })

当我使用 Morbo 时,会显示第一个警报,然后一旦返回来自 updateDeviceList 的结果 data,就会触发第二个警报,并且 devicelist div 的 HTML 被替换。

但是,当我使用 hypnotoad 时,第一个警报触发,然后第二个警报几乎立即触发。

在 `updateDeviceList' 完成之前。这就是非阻塞的意思吗?

有没有办法让它在继续之前等待我的数据首先返回?

非常感谢。

【问题讨论】:

  • 您能提供一个运行示例(Mojolicious::Lite)吗?这听起来很有趣,但如果没有更多代码,我无法复制。
  • 我也认为这个问题被忽略了,因为大多数 Mojo 用户只看perl 标签而不是mojolicious。我会添加它。
  • 我不太确定为什么会发生这种情况,但是当我在 apache 后面运行 hypnotoad 并且将 keepalive 设置为打开时,我遇到了类似的问题,KeepAlive off 为我修复了它

标签: jquery perl mojolicious


【解决方案1】:

你必须延迟这个函数,jQuery 有一个名为delay() 的函数可以让你设置倒计时。

alert('calling update device list');
$.get('updateDeviceList', function (data) {
    $(this).delay(1200).queue(function () { // Delay Queue will delay alert and update
        $("div#devicelist").html(data);
        alert('In update device list');
    });
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-08-25
    • 2011-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多