Woo Axios
<script>
// Here I define a path to 'myActions.php' file
const myActionsUrl = '<?php echo get_template_directory_uri() ?>'+'/myActions.php'
var params = new URLSearchParams();
params.append('action', 'my_own_function');
params.append('price', '199');
async function runPHP(){
axios.post(myActionsUrl, params)
.then(function (response) {
console.log(response)
})
.catch(function (error) {
console.log(error);
});
}
</script>
<button onclick="runPHP()">Run myActions!</button>
Cooperative Cassowary