You should not use your own AJAX handler PHP file. Your problem is that your file calls add_action() function and that function is part of WordPress, your file is not loaded in the WordPress context, so that function is not loaded. You need to load WP in your file first.
But, that is not a good way to do this. WordPress already has a dedicated AJAX handler file and you should be using that, and not your own file that might be a security risk.
This is a good article on using AJAX in plugins and it is on official WordPress Codex: AJAX in Plugins.
Related Posts:
- How can I make an Ajax login form work with FORCE_SSL_ADMIN enabled?
- Help making my pagination plugin better
- admin-ajax returning 400 error when request is made with Fetch API
- How to pass JavaScript variable to PHP in wordpress widget?
- Custom plugin giving: wp-admin/admin-ajax.php 400 (Bad Request)
- Ajax Load More and Masonry: is it possible to load admin-ajax.php in the front end?
- Errors while using ajax from external wordpress page
- I can’t access wordpress functions from an ajax php call
- Built in admin ajax hooks?
- delete_user_meta Delete one value out of array
- How to use wp-ajax in wp-cron
- Calling shortcode in wp_localize_script strips result
- how to use ajax to display from database and load more in wordpress plugin
- Only execute jQuery function(on document ready) on the page has shortcode from plugin [duplicate]
- Ajax with jQuery UI dialog not working
- Shortcode in AJAX popup
- How can I process xml file on upload?
- ajax front-end increment views on click
- $wpdb working with ajax but showing ajax error instead of success
- Why none of the plugins that have ajax doesn’t work in my website?
- Why do plugins that cause ‘unexpected output’ create AJAX problems?
- AJAX button run function
- How to Create a Custom Panel and Fields in Post Page [Plugin]
- WordPress Ajax Posting from App
- Ajax contact form widget plugin data not insert in database
- woocommerce_package_rates not fired when wordpress woocommerce accessed as non ajax
- Theme is Causing Ajax Conflicts for a plugin I cant identify it
- Why WordPress plugin url ajax doesn’t work?
- Search for categories
- AJAX in plugin wp_send_json() sending html
- Ajax call returning 0
- Ajax fail and get 504 error
- Ajax Search Lite: Customize Autoscroll
- Create tabs in admin options page from custom post type loop
- Display wordpress post’s in popup?
- Using color picker in plugin, does input attribute order matter?
- Ajax : Call undefined function plugin_function() … can’t call any plugin function
- AJAX call – failling to call do_action
- What are the Best Practises When Using AJAX in Plugin Development?
- AJAX fileupload – TypeError: not a function ajaxSubmit()
- Does having more than 30 Admin Ajax affects site performance (plugin)?
- Submit Form data to another page via Ajax (WordPress Way)
- How to display checked posts on another page over AJAX? (like comparasion style)
- PHP script from functions php is loaded via admin-ajax to div…and the result is 0, not the desired content
- where do I send my ajax calls
- Ajax save data to database on document ready, no data being saved
- Using WordPress to build membership Page
- don’t call ajax if not plugin page
- How to get specific string/value from an array? php [closed]
- woocommerce search by sku and title ajax
- How to request admin-ajax.php correctly when wordpress URL and site URL are different?
- WordPress API functions not working at AJAX functions.php call
- Passing PHP Variables to AJAX Loaded Pages
- wp_ajax action responds with 0
- Why AJAX response 0!
- Call ajax on the frontend
- Ajax request sends url rather than data
- grab or load text on demand
- best way to run a php script away from the template?
- admin-ajax.php 500 error when new users try to register
- Send Array from JS to php file then insert it in wp database through a plugin
- AJAX call inside plugin class is not getting to it’s response function
- wc_get_template_part doesnt display the content [duplicate]
- How do I reinit WordPress plugins dynamically using jS?
- Cannot pass value variable to WP AJAX functions
- JS working when used normally but not in wordpress
- Use AJAX to fetch Current Post Thumbnail for WordPress when Uploaded throughMedia Uploader Frontend
- How to avoid the 403 Forbidden error in a WP Plugin with Ajax and PHP
- Conditionally load public and admin code with AJAX working on both sides
- How to disable/enable PHP plugin functionality based on a TinyMCE toggle-button
- WordPress ajax error 400 bad request for sending data to remote site [duplicate]
- Ajax call to php function doesn’t work PHP code
- Get shortcode attribute for AJAX call
- ajax voting for custom post type
- Compare Ajax Data Results
- Why can’t I call a function from inside my registered AJAX function?
- Frontend AJAX Request causes Error: ‘Call to undefined function add_action’
- Ajax Load More on Hierarchical Categories
- WordPress environment not loading properly
- Creating new option (add_option) from AJAX – Settings API
- WordPress Feedback popup with date saved into table
- How to limit each front-end user to view just his own uploaded files on Amazon S3?
- Javascript not working
- Ajax specific template not loading in replacement of index.php
- WordPress ajax not working in registration
- AJAX login without a plugin does not work. when add a action to function.php
- Ajax return 0 in plugin – ajax only used in wp-admin
- AJAX doesn’t pass variables to the php function in the plugin
- ajax request not returning the result
- How do I convince this button to do something when it is clicked?
- Plugin constructor called multiple times
- My AJAX API plugin isn’t working
- ajax sends data to plugin
- Trouble After Update, Removing Plugin
- Help me with my first very basic plugin
- Jquery post responses 500 error after some time and lastly an 503 error
- Ajax button “Load more” is not loading correct language version posts for logged out users
- Inline AJAX script passing variables to PHP
- wordpress admin-ajax bad request 400
- Not applying update field (acf) in my plugin