I already have the wp hook code in place, and now I want to send error messages back to the front end to be placed in alert box or html element.
//my plugin
add_action('wp_ajax_track_upload', 'track_upload');
function track_upload() {
(!is_uploaded_file($_FILES['file']['tmp_name'])) {
//report error to front end
// i.e. send ajax response
}
}
// my front end form
<form method="post" action="
<?php echo admin_url( 'admin-ajax.php?action=musistic_track_upload' )?>"
enctype="multipart/form-data">
<input type="file" name="file" accept="audio/*">
<input type="submit" value="upload audio" name="submit"
id="submit_to_your_elders">
</form>
What's missing now? Do I need a js file to do some ajax handling? I read the codex article https://codex.wordpress.org/Class_Reference/WP_Ajax_Response, but it does not explicitly demonstrate how to tie in the wp_ajax_resonse in. How do I send a retrieve such a response? A code example relevant to my specific circumstance would greatly help a visual learner such as myself.