繁体   English   中英

附加Ajax数据后,jQuery无法调用插件吗?

[英]jQuery can't call plugins after appending Ajax data?

EDIT2:没关系,使其正常工作。 jQuery再次包含在用ajax调用的脚本之一中。 不管怎么说,还是要谢谢你。

编辑:这是一个改写的问题。 花了我一段时间才能找到问题所在。
在我用ajax加载某些内容后,无法调用插件函数(包括UI效果)。

原始问题具有.effect("pulsate",{},1000)调用,它解释了sarcastyxs的答案。 现在,我正在使用倒数计时插件尝试相同的操作。 出现相同的问题。

这是我的代码。 忽略它并没有多大意义,而是从更大的文件中删除了它。 本身的代码很好。 例如,如果我调用fadeOut()可以工作,但是如果我使用.countdown.effect ,则会出现上述问题。

var getOrderDetails= function(id){
    var that = this;
    $.ajax({
        type: "GET",
        url: "orderDetails.php",
        data: {id: id}, 
        success: function(data){
            //$("#orderDetails").html(data);
            $("#orderDetails").unbind().click(function(){
                var status = $("#orderDetails .orderStatus").text()
                acceptOrder(id, status);
            });
        }
    });
}

var acceptOrder = function(id, status){         
    var that = this;
    $.ajax({
        type: "GET",
        url: "orderStatus.php",
        data: {action: 'set', id: id, status: status}, 
        success: function(data){
            var nowTime = new Date();
            var countdownTime = nowTime.setMinutes(nowTime.getMinutes() + 2);
            $("#waitingOrders").countdown({until: countdownTime, compact:true, format: 'MS'});
        }
    });
}

$(document).ready(function(){
    $(".order").unbind().click(function() {
        var id = $(this).find(".orderId").text();
        getOrderDetails(id);
    });
});

当我注释$("#orderDetails").html(data)行(如代码中)时,倒数计时器将显示在orderDetails div中。
当我取消注释该行时,我countdown is not a function错误。 看着萤火虫中的dom,实际上在第一种情况下,我可以看到选择器具有.countdown函数,而在第二种情况下,它没有。

我在这里想念什么?
有人请帮忙,我已经坚持了几天。
试图用另一个函数来包装阿贾克斯成功的功能,并将它传递this的背景下,但它并不能帮助。 一样

您似乎缺少了jquery-ui一些核心功能。 您可以从jQuery网站下载自定义jquery-ui库。

您基本上要选择“ Effects core以及要在网站上使用的其他效果。 由于某些原因, effects core不是默认jQuery ui库的一部分。

暂无
暂无

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

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