Site icon Hip-Hop Website Design and Development

Ajax name from Plugin utilizing Class

I am making a plugin with a category and strategies.

This class will get referred to as by means of the theme ( laborious coded ) to enqueue and localize my js. it additionally prepares it for ajax. Nonetheless, i maintain getting ERROR: 400

POST http://www.devsite.native/wp-admin/admin-ajax.php 400 (Unhealthy Request)

I’ve ran ajax outdoors of a category in a number of plugins and on the capabilities.php with no points, however i am unable to get it to work inside a category.

That is my code:

class CCYTFeatured {
public perform __construct(){
        $this->cc_yt_scripts();
        add_action( 'wp_enqueue_scripts', array($this, 'cc_yt_scripts' ));

        add_action( 'wp_ajax_cc_yt_featured', array( $this, 'cc_yt_featured' ) );
        add_action( 'wp_ajax_nopriv_cc_yt_featured', array( $this, 'cc_yt_featured' ) );

}
// Load CSS AND JAVA FRONT END
public perform cc_yt_scripts() {
    wp_register_style( 'cc_yt_style',
        plugins_url( '/css/cc_yt.css', __FILE__ ),
        array(),
        cc_yt_version()
        );
    wp_enqueue_style('cc_yt_style');

    // JAVASCRIPT
    wp_register_script( 'cc_yt_javascript',
        plugins_url( '/js/cc_yt.js', __FILE__ ),
        array('jquery'),
        cc_yt_version(),
        true
    );
    wp_enqueue_script('cc_yt_javascript');
    wp_localize_script(
        'cc_yt_javascript',
        'cc_yt_script',
        array(
            'ajaxurl'   => admin_url( 'admin-ajax.php' , __FILE__ ),
            'ajax_nonce' => wp_create_nonce('my_nonce'),
        )
    );
}
public perform cc_yt_featured(){

    check_ajax_referer( 'my_nonce', 'safety' );
    echo json_encode('IM HERE, YOU CAN FIND US');
}
}

That is my JavaScript ajax name:

jQuery.ajax({
    url: cc_yt_script.ajaxurl,
    sort : 'POST',
    information: {
        motion : 'cc_yt_featured',
        safety: cc_yt_script.ajax_nonce,
        put up: 'bananas',
    },
    success: perform(response) {
        console.log('THIS IS THE RESPONSE:  '+ response);
    }
});

I maintain getting the identical error, i am unable to work out what’s flawed with my class:

That is how i name it.

$cc_yt = new CCYTFeatured;

I’ve that decision laborious coded inside a theme file. This does enqueue the types and scripts efficiently.

The ajax get is the next:

http://www.devsite.native/wp-admin/admin-ajax.php?motion=cc_yt_featured&safety=79e39910b8&put up=bananas

Anybody have any clue what i am doing flawed??

Thanks!