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 badges1 Answer
Reset to default 1Change the first param of wp_localize_script
to same as the handle of your main script file.
main
in this case.