Short answer — how can you solve the problem: When you call check_ajax_referer()
, use secure_nonce_name
as the first parameter, i.e. check_ajax_referer( 'secure_nonce_name', 'security' )
.
A Longer Answer
The first parameter (which is the nonce action) for check_ajax_referer()
needs to match the first parameter for wp_create_nonce()
, but in your code, they are secure-nonce-name
and secure_nonce_name
respectively, hence that would result in the error 403 which basically means “invalid nonce”.
So make sure the names are equal or that the nonce action is correct, e.g. use secure_nonce_name
with both the above functions:
// In the script in javascript_variables():
var ajax_nonce="<?php echo wp_create_nonce( "secure_nonce_name" ); ?>";
// Then in the AJAX callback (send_form()):
check_ajax_referer( 'secure_nonce_name', 'security' );
Additional Notes
- You should consider using the REST API which, unlike the
admin-ajax.php
, gives a better, human-friendly message when an error is encountered while processing the request.