WordPress api call using wp-ajax returns error 400

I figured this out after a night sleep. Sometimes our brains function like that. The problem was actually my call here, It should’ve been “add_foo” not “_add_foo” data: { // the value of data.action is the part AFTER ‘wp_ajax_’ in // the add_action (‘wp_ajax_xxx’, ‘yyy’) in the PHP above action: ‘_add_foo’ // ANY other properties … Read more

Can I use a jQuery Ajax request in Code Snippets Plugin for WordPress?

You’ll need to look at the server side logs to see what’s actually causing the 400. Without this, it’s just conjecture. With it, you should see exactly what’s causing the problem. However, I conjecture that you’re lacking authentication headers, or an authentication request. I’m not seeing anything related to authentication in your AJAX request, and … Read more

How do you create an attachment ID with Ajax submit? No page refresh

Here’s my solution for creating an attachment ID with a temporary title and the post_parent which it is attached to. My jQuery psuedo code, without the needless stuff: jQuery(‘.addImage’).live(‘click’, function() { jQuery.ajax({ type: ‘post’, url: ajaxurl, data: { action: ‘save_attachment’, _ajax_nonce: jQuery(‘#nonce_add’).val(), post_parent: jQuery(‘#post_ID’).val(), attach_title: ‘Attachment ‘ + size }, success: function( res ) { … Read more