最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugins - issue in wp_localize_script

programmeradmin1浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论