Sometime ago I’ve faced the issue with AJAX in wordpress that always returns 0 so i share these artical that help the beginner to work with ajax in wordpres.
wp_ajax and wp_ajax_nopriv are actions of wordpress cms.
This hook allows you to create custom handlers for your own custom AJAX requests. The wp_ajax_ hook follows the format “wp_ajax_$youraction”, where $youraction is your AJAX request’s ‘action’ property.
The wp_ajax_ hook only fires for logged-in users. If you need to also listen for Ajax requests that don’t come from logged-in users.
REF : https://codex.wordpress.org/Plugin_API/Action_Reference/wp_ajax_(action)