AJAX in plugin wp_send_json() sending html

I wrote a plugin that calls a PHP function from JQuery and the php sends a json response back to the Jquery using wp_send_json(). The functions are all called successfully, but the json request sends a lot of html to the jquery function every time. How do I make the json sent by the php function only a specific message?


jQuery( document ).ready( function() {

jQuery( ‘body’ ).on( ‘click’, ‘.wpm_mail_link’, function( e ) {

var varData = ‘name:foobar&email=bar@baz.foo’;

type: “POST”,
action: “wp_ajax_send_email”,
url: my_ajax_obj.ajax_url,
data: varData,
success: function(data) {
console.log(‘Ajax request successful’);




public function send_email() {
$response = array(
‘message’ => ‘Sent’,
‘ID’ => 1,

wp_send_json( $response );

Read more here:: AJAX in plugin wp_send_json() sending html

Leave a Reply

Your email address will not be published. Required fields are marked *