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.

Metabox cloning via Admin Ajax call issue

1st This isn’t a WP problem, but a jQuery problem. 2nd I used to develop my own set of classes for meta box and stopped about a month a ago and dropped them in favor of the RW Meta Box library. Meta Boxes are a big issue incl. saving the data, building an endless # … Read more

How-to debug wp_ajax_* hook callback?

The answer was as stupid as simple: I wrapped the init for the class in a ! is_admin() call. This successfully prevented the callback from beeing fired. Rule for AJAX loading Load it in public Don’t hide it behind a ! is_admin() call. The 2nd line from admin-ajax.php define( ‘WP_ADMIN’, true );