Trying to do this the WordPress way: wp_send_json_success
PHP processing save_form
return:
$response = array( 'messages' => $message );
wp_send_json_success( $response );
jQuery:
$j.ajax({
type: 'POST',
url: ajax_url,
data: {
action: 'save_form',
form_id: $j('#form_id').val(),
full_name: $j('#full_name').val(),
email: $j('#email').val(),
signup_nonce: $j('#signup_nonce').val()
},
success: function (response) {
console.log(response.messages);
},
error: function (response) { }
});
return false;
Response in the Inspector:
JSON:
success: true
data: Object { messages: "Enter a valid email address" }
messages: "Enter a valid email address"
but...
console.log(response.messages);
returns nothing.
What am I missing?
Thanks, Brad
alert("Hello")
statement? Alsoresponse.data.messages
should be used to get the desired data. – Vasanth Gopal Sep 9 '20 at 4:26