#46721 closed defect (bug) (invalid)
admin-ajax not working correctly
| Reported by: | beaconmartinb | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Administration | Version: | 5.1 |
| Severity: | major | Keywords: | |
| Cc: | Focuses: | ui, administration |
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
@
7 years ago
#2
@
7 years ago
- Keywords needs-codex removed
- Resolution → invalid
- Status new → 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
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Sorry the URL I'm testing within that is incorrect I'm actually testing with
/wp-admin/admin-ajax.php?action=beacon_podio-get_appsas it is in the Stack Exchange link