Use the built-in wordpress Ajax actions:
Your jquery will look like this:
$('#ajax_form').bind('submit', function() {
var form = $('#ajax_form');
var data = form.serialize();
data.action = 'MyPlugin_GetVars'
$.post('/wp-admin/admin-ajax.php', data, function(response) {
alert(response);
});
return false;
Your plugin code something like:
add_action("wp_ajax_MyPlugin_GetVars", "MyPlugin_GetVars");
add_action("wp_ajax_nopriv_MyPlugin_GetVars", "MyPlugin_GetVars");
function MyPlugin_GetVars(){
global $wpdb;
// use $wpdb to do your inserting
//Do your ajax stuff here
// You could do include('/wp-content/plugins/test/getvars.php') but you should
// just avoid that and move the code into this function
}
For more info please visit AJAX in Plugins
Related Posts:
- jQuery’s .on() method combined with the submit event
- Why use admin-ajax.php and how does it work?
- Why is die() used at the end of function that handles an Ajax request?
- Making my AJAX powered WordPress Crawlable
- Using Backbone with the WordPress AJAX API
- WordPress Ajax Data Security
- Why is a 500 error generated by admin-ajax.php not going into the Apache error log?
- admin-ajax.php doesn’t work when using POST data and Axios
- Custom Form with Ajax
- How to process ajax requests correctly using ajax plugins
- How do I hook an Ajax request into a PHP callback?
- Gutenberg – how to correctly perform ajax request on backend
- get_template_part execute with ajax
- How to add WordPress nonces to ajax request
- How is it possible that the function of the test page works, but it does not go live?
- How declare Ajax functions ussing SHORTINIT
- jQuery Autocomplete not working with wp_localize_script
- Load custom formatted comment with AJAX: reply link isn’t rendered?
- Is there a way to optimize function that is used for returning data in an ajax-call?
- WP REST API route request explain
- get_posts empty when called via Ajax
- admin-ajax.php mixed content
- WP-API and Basic Auth returning 403 on POST but not GET
- Is there a hook to process a backbone restful PUT request inside wordpress?
- Check if username exist with AJAX
- How to localized one js file for different actions?
- WooCommerce: Translation lost on AJAX call in Checkout page [closed]
- Async Loading of Custom Posts
- Call javascript function when category was added via ajax
- How to add WP API and JS featured image attachment
- Using AJAX with Forms
- json encode not work in wordpress
- wordpress and add actions to button by coding
- Get Author Post on author.php with AJAX
- Can’t publish post using ajax
- Ajax in plugin settings page returns 400 Bad Request
- Admin-Ajax Error
- Customizer AJAX using buttons
- WordPress Ajaxify Problem with Scroll-to [closed]
- Can’t trigger an AJAX function with a submit button in the dashboard
- AJAX Call is Only Returning 100 Results from Query
- AJAX and -1 response
- How to make custom button link on the WordPress Admin Bar run by AJAX
- Ways to load admin-ajax faster without initializing all plugins?
- is_single() conditional check inside ajax php function
- How to make registration form ajax?
- Specify ABSPATH in jQuery url
- WordPress action – Pass arguments into action in an AJAX call?
- 403 error When i send ajax request on WordPress website
- Ajax Call 400 Bad Request error with POST request but not with GET request
- While Ajax is working well, media upload isn’t showing the imagines
- How can I call an api before user login
- Problems with wordpress nonces in Ajax call
- Get post content and show it in a div
- Output multi-steps form results in same page
- Full Front End, AJAX comment system and comment reply script
- why does not work ajax that add_action registered in wordpress
- How to get post from pure frontend AJAX (using only post ID)?
- Auto load subcategories content with ajax
- Multiple AJAX requests using the same ajax_object.ajaxurl
- Is there a better way to access transients using javascript
- Ajax not working for certain user roles
- Filter custom post types by custom field using AJAX
- Tabbed feeds with ajax vs. without on homepage [closed]
- Get title and featured image using Ajax
- javascript onClick update user_meta from jquery.ajax
- How to ignore WP_ERROR caused by “get_the_excerpt” method in an AJAX call?
- WP_Query is not received in Ajax
- How do I mitigate replay attacks when talking about actions that shouldn’t happen twice?
- Updating Jquery object with newly created elements after AJAX call
- Not getting ajax success response on insert/update row to database
- Wp admin ajax load more
- wordpress ajax search posts
- Ajax call from Plugin using Class
- enqueue style using admin-ajax.php
- How to safely pass post_id and user_id via AJAX to the backend (prevent user from changing it via JS)?
- Can’t get next post info with ajax
- How to inject data content from external json into a modal, using UIkit?
- Ajax by worpdress affects called jquery inside template file
- AJAX form not working, still reloads on submit
- Call public static method from ajax ‘wpcf7_mail_sent’ hook
- Update user meta via ajax from frontend, saving issue
- How to get the admin page slug using wp_loaded hook?
- Edit user meta on front-end via AJAX
- How to paginate Ajax result
- Cannot access class properties from ajax call in wpordrpess
- why is my main.js not loading?
- Enqueue dynamically generated javascript
- First time doing Ajax with WP, how to do it?
- Unexpected WordPress search results
- WordPress Get Header and Footer using in Admin Area
- Tie the sending of an ajax request to WordPress hooks
- AJAX: admin-ajax.php is adding extra content to my script’s response – how to exclude header, footer, etc.?
- ajax page template
- apply_filters, EMBEDS and AJAX not a friends? [duplicate]
- Using Javascript Callback from plugin in a theme
- $wpdb Ajax not redirecting to main page
- how reduce fetch/XHR response time
- wordpress ajax bad request 400
- Custom WP rest api endpoint only working on non https?