Take a look at the codex for AJAX in Plugins. It provides example of how WordPress expects AJAX requests are made and how to return information back to the request in javascript.
The request gets routed through admin-ajax.php
which locates and action in PHP. The rest is up to you.
Note: you must echo/print the content for it to be returned in the body of the response. It’s helpful for it to be encoded with wp_json_encode()
as well.
Related Posts:
- Using AJAX in a plugin to submit form – REALLY confused
- Create custom HTML/JS app inside page
- Plugin Form Submitting to admin-ajax.php instead of admin-post.php
- Lead form that submits to 2 external APIs
- Page reload occurs before request finishes
- Difference Between Filter and Action Hooks?
- How can you check if you are in a particular page in the WP Admin section? For example how can I check if I am in the Users > Your Profile page?
- ajaxurl not defined on front end
- How to create an API for my plugin?
- How to store username and password to API in wordpress option DB?
- Why does WordPress add 0 (zero) to an Ajax response?
- Plugin Form Submission Best Practice
- $_POST form request with admin-post
- Is there a limit on making calls to WordPress.org API’s?
- Handling results from data hooked into admin_post
- Saving data-URI to media library
- What is the real intention for admin-post.php?
- Nonces can be reused multiple times? Bug / Security issue?
- How can I run AJAX on a button click event?
- How-to implement admin Ajax inside an admin WP_List_Table?
- Using filters and actions for plugin API?
- What is the recommended way to create plugin administration forms?
- WordPress and multithreading
- What is nonce and how to use it with Ajax in WordPress? [duplicate]
- Empty POST data on server on AJAX request using Angular $http
- Using AJAX in FrontEnd with WordPress Plugin Boilerplate (wppb.io)
- Build path for a custom portfolio plugin
- permalinks with get variables
- wp_localize_script $handle
- How to enable users to down-vote in this simple voting counter (that uses the post meta)?
- Post from front-end with post types, categories and taxonomies
- Front-End Form Submission in Shortcode
- Check spam in custom form – akismet
- Adding callback function for wp_ajax_ has no effect
- get all products of one category
- Get returned variable from a function to add_shortcode function
- Use a PHP file as action for a form in a WordPress plugin, what’s the correct way?
- Plugin Settings not Saving on Ajax re-ordered table
- How to post form in ajax mode and handle it in wordpress
- Build dynamic page from cURL (HTML page) response with plugin
- Using Ajax call in jQuery doesn’t work in widget
- How to override a function call in functions.php?
- wp_enqueue_style built in styles
- WP_LOCALIZE_SCRIPT doesn’t work
- Timeout on Admin-Ajax?
- Admin-ajax.php appending a status code to ajax response
- Front-End Interfaces Without Shortcodes
- Comment `Reply` link doesn’t work if comments are loaded from ajax
- Best Practices for Creating and Handling Forms with Plugins?
- Should I ask my Twitter plugin users to create their own Twitter App and API Keys to use my plugin?
- Ajax in WordPress – path issue
- Cannot search post by taxonomy
- Plugin options page – form with two different submit buttons
- WordPress Ajax callback function from plugin – OOP
- WP AJAX is not working, always returns 0
- Does WordPress’s HTTP API use any caching?
- Ensure function has completed before allowing another Ajax call
- How to sanitize user input?
- Frontend Ajax call not working using wp_ajax, wp_enqueue_script and wp_localize_script
- Fetching the value of forms in WordPress AJAX
- include wp-blog-header not working on MAMP
- Any problem in using native jquery ajax style instead of using admin-ajax.php?
- Slow WP_query due to nested wp_query. Need Suggestions
- WooCommerce registration password field not displaying
- wordpress plugin php file processing form
- Show special field when correct shipping is chosen
- .mo translation strings not loading in PHP scripts that handle AJAX calls
- How can I pass get_the_author_meta(‘user_email’) through the REST API?
- How to add custom fields to the all users page
- Example Dashboard Widget, Cancel not working
- Woocommerce checkout update totals with datepicker
- Including the necessary functions for a custom ajax registration form
- Error on inserting a form value to database
- Multiple options pages validation for a plugin
- How can I rewrite a URL to pass requests to a custom method via AJAX? (I can’t use admin-ajax.php)
- How to localize admin.php only once
- get post attachment using ajax
- Dashboard – get status and position of metaboxes and pass them to ajax method
- Using a custom plugin to capture input data via Ajax and PHP
- Amending REST API function without deactivate/activate plugin every time changes is made
- Create a new post using rest api and save featured image using an external image url
- how to search users by ajax live search
- Why does wp_remote_post returns an empty body response on certain endpoints?
- Form doesnt save to database
- Adding custom end points, No error line
- Sending post request with wp_remote_post not working correctly
- wp.template() returns tags in Ajax response
- How to get Metabox custom field to show checked if value is updated using post meta query?
- Storing data in wordpress database from ajax call from different website
- woocommerce_checkout_order_processed hook executing function twice
- Fatal error: Uncaught Error: Call to undefined function get_option()
- Plugin Development for registered users
- Is there documentation reference for forms in menu and setting pages?
- Use just a shortcode from another page
- Input in plugin widget does not allow spaces
- template_redirect or admin-ajax.php?
- Avoid updating post when sending POST or GET request to post.php
- What to hook into to check a value before a post is published?
- how to get context information inside my funcion
- AJAX form post returns 0