Using AJAX to submit and return data inside the WordPress Plugin Boiler Plate framework

Take a look at the codex for AJAX in Plugins. It provides example of how WordPress expects AJAX requests are made and how to return information back to the request in javascript.

The request gets routed through admin-ajax.php which locates and action in PHP. The rest is up to you.

Note: you must echo/print the content for it to be returned in the body of the response. It’s helpful for it to be encoded with wp_json_encode() as well.