Tag nonce
How To Use The WordPress Rest Api With Javascript Fetch
Expose the REST root URL and a nonce with wp_localize_script(), then call any endpoint from JS.
How To Make An Ajax Request In WordPress With Admin-Ajax.php
Register a PHP handler with the wp_ajax_ and wp_ajax_nopriv_ hooks, then call it from JavaScript with fetch(). This example requires the lotgrafixData object from the wp_localize_script() post.
How To Pass Php Data To Javascript In WordPress With Wp_Localize_Script
Use wp_localize_script() to expose PHP values such as the AJAX URL, a nonce or the site URL to your JS file.


