AJAX action through direct link

Question

I have an existing AJAX action that’s already defined by the theme I’m using. The action deletes a search item request, and I’d like to use it as a direct link – like an Unsubscribe link – emailed to the user along with the search results…

Something like the following URL: https://domain.tld/wp-admin/admin-ajax.php?action=delete_saved_search_item=&search_item_id=17 but I get a 0 on the screen and a 400 Bad Request in the Headers.

Basically in the JS it’s defined like this:

            $.post(ajaxurl,
                {
                    action: 'delete_saved_search_item',
                    search_item_id: search_item_id,
                },
                function (response) {
                    response = JSON.parse(response);
                    if (response.success) {
                        search_item.remove();
                    }
                }
            );

so I suppose it expects a POST request, not a GET one… Is there any workaround to make this work? Like creating a page with a custom cURL that would imitate the POST form submission? Anyone done something like this? The good thing is I didn’t notice any use of nonce, so I suppose this alone makes it easier to handle, doesn’t it?

0
Faye D. 3 months 2022-05-29T06:27:25-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse