Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/236.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 点击事件赢得';在AJAX过滤器操纵DOM之后,t激发_Php_Jquery_Ajax_Wordpress_Woocommerce - Fatal编程技术网

Php 点击事件赢得';在AJAX过滤器操纵DOM之后,t激发

Php 点击事件赢得';在AJAX过滤器操纵DOM之后,t激发,php,jquery,ajax,wordpress,woocommerce,Php,Jquery,Ajax,Wordpress,Woocommerce,我正在一个电子商务网站上工作,该网站有一个AJAX过滤器,它可以根据每个产品属性操作dom 我正在编写另一个AJAX调用,以便在单击每个产品时获取更多的产品属性 这是我的AJAX调用 $('.each-product').on('click', function (e) { /** Prevent Default Behaviour */ e.preventDefault(); /** Get Post ID */ var post_id = $(this)

我正在一个电子商务网站上工作,该网站有一个AJAX过滤器,它可以根据每个产品属性操作dom

我正在编写另一个AJAX调用,以便在单击每个产品时获取更多的产品属性

这是我的AJAX调用

$('.each-product').on('click', function (e) {

    /** Prevent Default Behaviour */
    e.preventDefault();

    /** Get Post ID */
    var post_id = $(this).attr('id');
    var response_class = '.' + post_id + '-ajax-response';


    /** Ajax Call */
    jQuery.ajax({
        type: 'POST',
        url: ajaxurl,
        data: { action: 'product_extra_info', id: post_id },
        beforeSend: function () {
            $(response_class).show().html("Loading...");
        },
        success: function (data) {
            $(response_class).show().html(data);
            //alert(data);
        }

    });
    return false;
});
请参阅事件委派。使用
单击
,您无法绑定动态添加到DOM中的内容。将您的代码切换为启用,如下所示:

$('.products').on('click', '.each-product', function (e) {

    /** Prevent Default Behaviour */
    e.preventDefault();

    /** Get Post ID */
    var post_id = $(this).attr('id');
    var response_class = '.' + post_id + '-ajax-response';


    /** Ajax Call */
    jQuery.ajax({
        type: 'POST',
        url: ajaxurl,
        data: { action: 'product_extra_info', id: post_id },
        beforeSend: function () {
            $(response_class).show().html("Loading...");
        },
        success: function (data) {
            $(response_class).show().html(data);
            //alert(data);
        }

    });
    return false;
});

您应该将click事件绑定到那些动态创建的DOM元素。(由延迟加载创建的)控制台中显示的任何错误?使用事件委派。请阅读jQuery的
。on
上的文档,了解其工作原理。@vrej请发布您的jQuery函数代码,用于定义在ajax筛选器之后调用的单击函数。。