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
- Why does WordPress add 0 (zero) to an Ajax response?
- $_POST form request with admin-post
- Saving data-URI to media library
- What is the real intention for admin-post.php?
- How can I run AJAX on a button click event?
- Using filters and actions for plugin API?
- WordPress and multithreading
- Empty POST data on server on AJAX request using Angular $http
- 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
- How to post form in ajax mode and handle it in wordpress
- Using Ajax call in jQuery doesn’t work in widget
- How to override a function call in functions.php?
- Timeout on Admin-Ajax?
- Front-End Interfaces Without Shortcodes
- Comment `Reply` link doesn’t work if comments are loaded from ajax
- Ajax in WordPress – path issue
- Does WordPress’s HTTP API use any caching?
- include wp-blog-header not working on MAMP
- Slow WP_query due to nested wp_query. Need Suggestions
- WooCommerce registration password field not displaying
- wordpress plugin php file processing form
- 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
- 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
- how to search users by ajax live search
- Form doesnt save to database
- Adding custom end points, No error line
- Sending post request with wp_remote_post not working correctly
- Storing data in wordpress database from ajax call from different website
- Input in plugin widget does not allow spaces
- Avoid updating post when sending POST or GET request to post.php
- Remove entire [$key] from array stored in custom field using Ajax – unset($array[$key]); not working
- How can I add a simple custom field to my plugin?
- Ajax is not working in a loop
- Submit Form data to another page via Ajax (WordPress Way)
- Run JavaScript validation script on form submit in plugin
- I am unable to save my data from a form
- Encoding Method for URLs?
- Google credentials and redirect URI for Google OAuth2 in a WordPress plugin, questions
- Setting a JSON web token from a secondary api as a secure cookie on WordPress
- How do I get rid of my inclusion race-condition on wp_enqueue_script
- Issues Updating Post Meta with AJAX (Seems simple but cannot figure it out)
- Form using admin-post.php gives 404 after submission
- AJAX call to admin-ajax.php by subscriber returns home page
- Ajax function is not working on WordPress
- Best way to ping for the API changes in the wordpress?
- About a programming language starts with [closed]
- Workflow for new importer plugin – your advices?
- Form submission to another page returning 404 error [duplicate]
- AJAX request not routing through proxy
- Widget internal hooks and functions
- Allow REST API Endpoint to specific user and hide from public
- Ajax on the Administration Side of plugin – returns 0
- Custom Endpoint – Does it possible to use PUT method with WP API Rest?
- Ajax action has 200 status but response of No response data available for this request
- GET request return value as error instead of success
- How to query a nested field in wordpress api using _fields param
- Trying to run a Ajax request from a checkout form in woocommerce via a custom plugin
- ajax stopped working when not logged in wordpress
- call funcution when clicking submit
- ajax response strips multidimensional array and unable to decode
- 400 Bad Request and illegal invocation in wp_ajax based on processData set to false or true
- Rate limiting ajax requests in WordPress
- How do I make secure API calls from my WordPress plugin?
- AJAX call of function containing javascript which is not loaded (Plugin development)
- How to include files in the loop via ajax
- How to handle ajax Request in a complex-structured plugin?
- Filterable posts using categories
- How to get values from Tinymce visual editor popup?
- How to Maintain url on form submit
- PHP includes with AJAX actions
- WordPress function is not called and ajax return 0
- Ajax call not working with
- Form and database, plugin development
- Do you see any problems (mainly security-related) with how I’ve used wp_ajax_* actions?
- Can a plugin differentiate syndication feeds from actual site views?
- Capturing POST data
- Multi-part form and wp_redirect()
- Fatal error: Call to a member function query() on a non-object in my ajaxpage
- modify buddpress adminbar only in admin pages
- How to update WordPress Plugins in your own maintance application?
- Return custom product in ajax call loop