#46721 closed defect (bug) (invalid)
admin-ajax not working correctly
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | major | Version: | 5.1 |
Component: | Administration | Keywords: | |
Focuses: | ui, administration | Cc: |
Description
So According to the Codex and a 12 Gold Badge wordpress.stackexchange member the following code should work, but it does not I think there is a bug in the add_action handler for 'wp_ajax' because the action is never being run.
So this is my simple test case:
<?php class testClass { public function __construct(){ echo "hello world"; add_action('wp_ajax_beacon_podio-get_apps', array($this, "get_apps")); } public function get_apps(){ if(isset($_POST['app_id'])){ $app_id = $_POST['app_id']; die("Request is valid"); }else{ die("Invalid request"); } } } new testClass();
Testing with request to from browser with logged in admin account:
/wp-admin/admin-ajax.php?action=wp_ajax_beacon_podio-get_apps
Expected Result
hello worldInvalid request
Actual Result
hello world0
The question an answer that made me think this is a bug: https://wordpress.stackexchange.com/questions/332878/wordpress-ajax-action-how-to-return-content
Change History (3)
#1
in reply to:
↑ description
@
6 years ago
#2
@
6 years ago
- Keywords needs-codex removed
- Resolution set to invalid
- Status changed from new to closed
There's no bug for this ticket. Like what the reporter mentioned on comment 1. The correct url should be
wp-admin/admin-ajax.php?action=beacon_podio-get_apps
and not
wp-admin/admin-ajax.php?action= wp_ajax_beacon_podio-get_apps
Note: See
TracTickets for help on using
tickets.
Sorry the URL I'm testing within that is incorrect I'm actually testing with
/wp-admin/admin-ajax.php?action=beacon_podio-get_apps
as it is in the Stack Exchange link