All AJAX requests return a 400 error

I have not tested your code, but one problem I noticed is the contentType property in your $.ajax() call: contentType: ‘application/json; charset=utf-8’, because that way, (from the PHP side) the action (i.e. ajax_load_more) is not available in $_REQUEST[‘action’] which WordPress uses to determine the AJAX action being called, and when the action is not known, … Read more

WordPress admin-ajax.php 400 bad request

Your full form code does contain a hidden input named action with the value send_form. However, you’re not sending it correctly, because of the the contentType part in your JS script, which submits the form data as a JSON payload, but note that the old admin-ajax.php endpoint doesn’t support JSON payload, hence $_REQUEST[‘action’] would be … Read more

AJAX and -1 response

You should end all “async” functions with die() or exit, otherwise WordPress does it for you returning -1.

How do I Import / Upload Files with jQuery AJAX?

I haven’t tried but i think you need to add FormData object directly as data parameter. Something like this var ajaxData = new FormData(); ajaxData.append( ‘action’, ‘ajax_handler_import’ ); ajaxData.append( ‘_ajax_nonce’, importNonce ); // or maybe skip the nonce for now jQuery.each($(‘#fileImportData’)[0].files, function(i, file) { ajaxData.append(‘file-‘+i, file); }); The rest of your code goes as it … Read more

Pagination Using ajax

I had got the ans. First you have to add following code in your function.php to call ajax in your template** add_action( ‘wp_ajax_demo-pagination-load-posts’, ‘cvf_demo_pagination_load_posts’ ); add_action( ‘wp_ajax_nopriv_demo-pagination-load-posts’, ‘cvf_demo_pagination_load_posts’ ); function cvf_demo_pagination_load_posts() { global $wpdb; // Set default variables $msg = ”; if(isset($_POST[‘page’])){ // Sanitize the received page $page = sanitize_text_field($_POST[‘page’]); $cur_page = $page; $page -= … Read more