I try to load a post with Ajax.
functions.php
:
function my_action_callback() {
wp_localize_script('jscustom', 'ajax_custom', array(
'ajaxurl' => admin_url('admin-ajax.php')
));
wp_enqueue_script('jscustom');
}
add_action('wp_ajax_my_action', 'my_action_callback');
jQuery code in custom.js
:
jQuery(window).load(function() {
var morebutton = jQuery('#load-more'),
archive = morebutton.rel,
deftext = morebutton.text(),
page = 1;
morebutton.click(function(e){
e.preventDefault();
page++;
morebutton.text(ajax_custom.loading);
jQuery.post(ajax_custom.ajaxurl, {action:'load_more', page:page, archive:archive}, function(data){...
When I press the “load more” button, I get an error:
ReferenceError: ajax_custom is not defined
What is wrong?