Ajax form submission from admin panel

File Upload via Ajax is a bit tricky, but manageable. Add some additional form fields (nonce and ajax_action) to your form in suite_export_import_menu(): function suite_export_import_menu(){ ?> <h2>Suite Report Export/Import </h2> <div id=”export_import_form”> <p id=”custom_ajax_call_process”>Uploading…</p> <p id=”custom_ajax_call_result”></p> <form action=”<?php echo admin_url(‘admin-ajax.php’); ?>” method=”post” enctype=”multipart/form-data” target=”upload_target”> <input type=”hidden” name=”action” value=”export_vacancy”> <input type=”hidden” name=”subaction” value=”imp_vacancy”> <input type=”file” name=”file_source” … Read more

store/cache ajax sent data to avoid repeated request

Attempting to answer this question directly: if the data you are returning is exactly the same each time, you can send cache control / expires headers with your AJAX response so that the browser knows not to request again for a while. // ask the browser to cache this response, to reduce requests $expires = … Read more

Refused to execute script from ‘***’ because its MIME type (‘text/html’) is not executable, and strict MIME type checking is enabled

The error is most likely correct (and is most likely related to browser upgrade than any WP version change) and your theme/plugin does fishy things. The ajax enedpoint should be uses to return data – html/json/xml. WordPress will use the text/html mime type for all responses from the ajax endpoint without any simple way I … Read more

How to add WordPress nonces to ajax request

I figured it out. Simply, in my request, under data, I added “nonce” : “<?php echo wp_create_nonce( ‘refresh_my_plugin’ ); ?>” then to verify if (isset($_POST[‘refresh_my_plugin’])) if ( wp_verify_nonce( $_POST[‘nonce’], ‘refresh_my_plugin’ ) ) refresh_my_plugin(); With incorrect wp_verify_nonce, I instead get a 403, which is reflected on the button with the error handler.