ajax - add action in class not running, always return 0 -


i'm trying run ajax action in custom class seems not call @ action (class method actually). scripts loaded, means class included , instanciated.

class myclass {      public function __construct() {          add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) );         add_action( 'wp_ajax_loadmore', array( $this, 'loadmore' ) );         add_action( 'wp_ajax_nopriv_loadmore', array( $this, 'loadmore' ) );      }      public function scripts() {          wp_register_script( 'filter', 'assets/js/filter.js', array( 'jquery' ), null, true );         wp_enqueue_script( 'filter' );         wp_localize_script( 'filter', 'filter', array(             'ajaxurl'        => admin_url( 'admin-ajax.php' ),             'loadmore_nonce' => wp_create_nonce( 'loadmore_nonce' )         ) );      }      public function loadmore() {          if ( ! check_ajax_referer( 'loadmore_nonce', 'loadmore_nonce', false ) )             exit;          @header( 'content-type: application/json' );         echo json_encode( array(             'foo' => 'bar'         ) );         exit;       }  } 

in js file wrote following:

$('#loadmore a').on('click', function(e) {      e.preventdefault();      $.ajax({         type: 'post',         datatype: 'json',         url: filter.ajaxurl,         data: {             'action': 'loadmore',             'loadmore_nonce': filter.loadmore_nonce         },         success: function (response) {              console.log(response);          }     });  }); 

the ajax success callback returns 0

and 0 comes die('0'); @ end of admin-ajax.php file


Comments