show 0 after wp ajax response in html prevent but i cant use wp_die or exit is there another way to hide 0
Yes, you can use the "return" statement in your PHP function instead of "wp_die" or "exit". This will allow the function to continue running and return the value to the AJAX request without the "0" being displayed.
For example:
function my_ajax_function() {
// do some processing here
$result = 123; // your result value
// return the result value
return $result;
}
// AJAX request handler
add_action( 'wp_ajax_my_ajax_request', 'my_ajax_function' );
add_action( 'wp_ajax_nopriv_my_ajax_request', 'my_ajax_function' );
Then in your JavaScript code, you can use the "success" callback function to handle the response:
jQuery.post( ajaxurl, {
action: 'my_ajax_request',
// other data to send
}, function( response ) {
// handle the response
if ( response !== '0' ) {
// do something with the response value
}
});
Note that this approach assumes that your PHP function is actually returning a value and not just outputting something to the page. If that's the case, you may need to modify your function to return the desired result instead of outputting it directly
原文地址: https://www.cveoy.top/t/topic/fiXG 著作权归作者所有。请勿转载和采集!