I had this issue because I was using:
echo admin_url(); to get the ajaxurl,
after changing to
echo admin_url('admin-ajax.php');
it worked!