1 | initial version |
WordPress Admin Ajax requests can be terminated programmatically using the wp_die()
function. This function will stop the script execution and return an error message to the browser.
To use wp_die()
to terminate an Ajax request, you can add the following code to your Ajax callback function:
function my_ajax_callback() {
// Perform some tasks here
// Terminate the request
wp_die();
}
You can also pass an error message to the wp_die()
function to provide more information to the user:
function my_ajax_callback() {
// Perform some tasks here
// Terminate the request with an error message
wp_die( 'An error occurred while processing the request.', 'Error', array( 'response' => 500 ) );
}