The first issue I see is the ajax url is incorrect. Your wp_localize_script()
has the handle name ‘main’, not ‘ajax_object’.
url: main.ajaxurl
Also, where is the callback code to handle the get_program_by_category
ajax action? You’re missing two actions.
add_action( 'wp_ajax_my_action', 'my_action_callback' );
add_action( 'wp_ajax_nopriv_my_action', 'my_action_callback' );
See the WordPress Codex to learn more about using the AJAX API.
Update #1
Try using this to debug. You should get a popup telling you either “Success” or “Failed”. Also, the data will be logged to the brower console.
$.ajax( {
url: main.ajaxurl,
type: 'POST',
dataType: "html",
data: {
'action': 'get_program_by_category',
'datas': category
}
} ).done( function (r) {
console.log(r);
if ( r.success ) {
alert( 'Success!' );
} else {
alert( 'Failed!' );
}
} );