WordPress send Ajax where click button

@sergio Here is the working answer you can check if there is still any issue paste it here and it if it works well you can upvote the answer to help others. The issue it when you click button your $(this).prop(‘files’)[0] is not working because not this scope to the button element. $(‘body’).on(‘click’, ‘#enviar_fichero’, function() … Read more

wp-admin/admin-ajax.php 400 Bad request (chrome console)

To simplify your process and prevent redundant conditional checks just stack the two actions on top of each other. wp_ajax_ runs for authenticated users and thus does the conditional check of is_user_logged_in() anyway. wp_ajax_nopriv_ does the same thing, but looks for unauthenticated users. The actions themselves run the conditions anyway, so you needn’t run it … Read more

Ajax call to a function in another module returns a 400 (Bad Request) error

Assuming your apps/save-books.php file contains the save_book_form() function and the wp_ajax_save_book_form hook, the problem is that you’re only including this file inside the admin_menu hook. The admin-ajax.php file does not run the admin_menu hook, so your apps/save-books.php file won’t be loaded for admin AJAX requests, which means that your action is never hooked. You need … Read more

AJAX request blocked by CORS policy

The problem was that the PHP AJAX function was redirecting to another page, which caused these issues. I decided to just generate a link instead of redirecting.