function my_simple_ajax() {
// Magic happens here.
echo json_encode( 'Welcome to Tori Ajax' );
}
if ( function_exists( 'toria_add_ajax' ) ) {
toria_add_ajax(
'simple',
'my_simple_ajax',
get_stylesheet_directory_uri() . '/inc/my_custom_ajax/toria_ajax.js'
);
}
inc/my_custom_ajax/toria_ajax.js
.
function tori_ajax() {
jQuery.ajax({
type: "post",
url: toria.ajax_url, // admin-ajax.php path,
data: {
action: toria.action, // action
nonce: toria.nonce, // pass the nonce here
},
success: function (data) {
console.log(data.trim());
//alert(data.trim());
},
error: function (errorThrown) {
console.log(errorThrown);
}
});
}
tori_ajax();// call the function.