Set cors header for ajax requests

The send_headers hook is not fired during an (admin) AJAX request (because there is no “main WordPress query”, so the wp() function doesn’t run and therefore that hook doesn’t get fired either), hence if you want to send the CORS header (and any other headers), then just call header() from within your AJAX callback, like … Read more

Ajax call returning 0 in page template

3 major problems: extract, is dangerous and introduces major security issues. It’s also completely unnecessary return instead of wp_die, you’re meant to echo the output and then exit/die. If you do not then WP will continue to handle the AJAX request, assume no handler was found, and print 0 JSON data type, the old legacy … Read more