我编写了一个插件,从JQuery调用PHP函数,PHP使用wp_send_json()
. 这些函数都被成功调用,但json请求每次都会向jquery函数发送大量html。如何使php函数发送的json仅为特定消息?
JQUERY:
jQuery( document ).ready( function() {
jQuery( \'body\' ).on( \'click\', \'.wpm_mail_link\', function( e ) {
var varData = \'name:foobar&[email protected]\';
jQuery.ajax({
type: "POST",
action: "wp_ajax_send_email",
url: my_ajax_obj.ajax_url,
data: varData,
success: function(data) {
console.log(\'Ajax request successful\');
console.log(data.message);
}
});
});
});
PHP:
public function send_email() {
$response = array(
\'message\' => \'Sent\',
\'ID\' => 1,
);
wp_send_json( $response );
}