【问题标题】:jQuery not working on Ajax loaded div contentjQuery 无法处理 Ajax 加载的 div 内容
【发布时间】:2020-07-26 19:36:59
【问题描述】:

我的页面上有一个 div,它通过 ajax 检查并根据 MySQL 查询结果加载内容。

页面上加载的 jQuery 不适用于 ajax 更新的内容。

我使用的jQuery代码如下

function getLiveStreamAuction() {
        
            var ajaxurl = saajaxurl+'=get_live_stream_auction';
        
        jQuery.ajax({

            type : "post",
            encoding:"UTF-8",
            url : ajaxurl,
            dataType: 'json',
            data : {action: "get_live_stream_auction", "last_activity" : SA_last_activity},
            success: function(response) {
            console.log("success");
            jQuery(".woocommerce-live-stream-container").replaceWith(response.screen_text);
            },
            error: function(response){
                console.log("fail");
            }
        });
}

就像 jQuery 不适用于更新的内容,到目前为止我找不到解决方法。任何帮助将不胜感激。

【问题讨论】:

  • 具体是什么不起作用?还有response.screen_text 是什么样的?
  • jQuery 函数将无法处理最初加载页面时不存在的元素(例如使用 ajax 加载的元素),除非在从 ajax 加载内容后调用该函数。

标签: jquery ajax wordpress


【解决方案1】:

正如学习者所引用的,在窗口加载时定义的 jQuery 函数不适用于 ajax 调用加载的内容。在ajax调用后调用必要的函数后,一切正常运行并解决了问题。非常感谢。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-29
    • 1970-01-01
    • 1970-01-01
    • 2018-10-14
    • 2017-03-15
    • 1970-01-01
    • 2013-08-06
    • 1970-01-01
    相关资源
    最近更新 更多