plugins - issue in wp_localize_script

I am initializing wp_localize_script after enqueueing scripts like that wp_enqueue_script('main',get_template_

I am initializing wp_localize_script after enqueueing scripts like that

wp_enqueue_script('main',get_template_directory_uri().'/js/mains.js','','1.1',true);
    wp_localize_script( 'ajax-pagination', 'ajaxpagination', array(
        'ajaxurl' => admin_url( 'admin-ajax.php' )
    ));

but i am unable to get it in jquery file/code jquery code is

(function($) {
    $(document).on( 'click', '.page-numbers', function( event ) {
        event.preventDefault();
        $.ajax({
            url: ajaxpagination.ajaxurl,
            type: 'post',
            data: {
                action: 'ajax_pagination'
            },
            success: function( result ) {
                alert( result );
            }
        })
    })
})(jQuery);

on clicking i am seeing the error ajaxpagination is not defined , what can be the possible solutions for this ?

I am initializing wp_localize_script after enqueueing scripts like that

wp_enqueue_script('main',get_template_directory_uri().'/js/mains.js','','1.1',true);
    wp_localize_script( 'ajax-pagination', 'ajaxpagination', array(
        'ajaxurl' => admin_url( 'admin-ajax.php' )
    ));

but i am unable to get it in jquery file/code jquery code is

(function($) {
    $(document).on( 'click', '.page-numbers', function( event ) {
        event.preventDefault();
        $.ajax({
            url: ajaxpagination.ajaxurl,
            type: 'post',
            data: {
                action: 'ajax_pagination'
            },
            success: function( result ) {
                alert( result );
            }
        })
    })
})(jQuery);

on clicking i am seeing the error ajaxpagination is not defined , what can be the possible solutions for this ?

Share Improve this question asked Jun 1, 2019 at 15:25 FluttererFlutterer 1159 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Change the first param of wp_localize_script to same as the handle of your main script file.

main in this case.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745445117a4628013.html

相关推荐

  • plugins - issue in wp_localize_script

    I am initializing wp_localize_script after enqueueing scripts like that wp_enqueue_script('main',get_template_

    6小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信