Cross origin ajax request always returns 0 when calling get_current_user_id();

Don’t write your own bootstrapper, use Ajax hooks via wp-admin/admin-ajax.php

Documentation: https://codex.wordpress.org/AJAX_in_Plugins

Then you can be sure WordPress has included all the functions you need.


Update:

I missed the bit about posting from local machine to remote server. If your JavaScript is running on another domain, it won’t be sending back your web server’s login cookies. CORS cannot help you with that.