You can use like this for send ajax…
function my_action_javascript()
{
?>
<script type="text/javascript">
jQuery(document).ready(function ($) {
var data = {
'action': 'my_action',
'whatever': '1'
};
$.post(ajaxurl, data, function (response) {
if ($('#menu_order').val() == '' || $('#menu_order').val() == '0')
$('#menu_order').val(response);
});
});
</script> <?php
}
add_action('admin_footer', 'my_action_javascript');
function my_action_callback()
{
$whatever = intval($_POST['whatever']);
//$whatever += 1;
echo $whatever;
wp_die(); // this is required to terminate immediately and return a proper response
}
add_action('wp_ajax_my_action', 'my_action_callback');
Related Posts:
- How to call a PHP function with Ajax when the user clicks a button
- Delete row of custom table in WordPress using AJAX
- Ajax form submission from admin panel
- How to securely add an Ajax button to a WP Admin page?
- wp_remote_get() to get AJAX url /wp-admin/admin-ajax.php
- AJAX requests broken due to HTTPS for wp-admin
- wp-admin AJAX with Fetch API is done without user
- WP Admin AJAX Security – using POST to include a relative URL
- Updating a checkbox value to database for specific row in table
- WordPress Ajax Not Working ( Custom Admin page)
- Why a strange discrepency between get_current_user_id() when using AJAX versus output of document.cookie?
- Can’t get result from sql using ajax result
- Pass additional parameter with async upload
- Use WP admin AJAX url to hide API key
- Ajax insert or update data
- Creating an auto result search bar
- Ajax call in wordpress not working for subscriber user
- Sql formatting for post data within function
- Preprocess submitted data
- How to check nonce lifetime value of plugins?
- WordPress ajax response save into database
- admin-ajax.php returns 0 even when the post status code is 200 OK
- Counting Posts with multiple taxonomy and terms condition using MySQL and AJAX
- Can I use application/json content type in WordPress
- Not getting ajax success response on insert/update row to database
- wordpress admin ajax trash_comment
- AJAX is not submitting data to database
- Ajax call not working anymore
- WorddPress website admin part not working correctly – I think ajax/json issue
- How modify comments metabox on post edit screen in WordPress?
- AJAX call in backend results in empty update_option
- Weird admin-ajax.php problem
- WordPress Get Header and Footer using in Admin Area
- Ajax Form data is not posted back to the get_results()
- get_comments() returns empty array if called through AJAX
- Can’t access data from database using AJAX
- WordPress blocking polling request when signed into Admin
- Translating wordpress foreach to ajax
- WordPress Ajax – looping data into a table
- $wpdb Ajax not redirecting to main page
- Adding custom fields to Wired Impact Volunteer Management Plugin
- Successful ajax call returns lots of whitespace and text of code with 0
- randomly get 400 error while user is logged in wp_ajax
- Using $.ajax getting 500 error
- Access-Control-Allow-Origin error sending a jQuery Post to Google API’s
- Show spinner GIF during an $http request in AngularJS?
- ASP.NET MVC controller actions that return JSON or partial html
- How to check if I am in admin-ajax.php?
- Saving (Updating) Post / Page Edits With AJAX
- AJAX handler throws 400 (Bad request) – why?
- Is there a hook that fires before an ajax call?
- AJAX request from Chrome Extension to WordPress Website
- Minimal WordPress load for only `get_option` to work (because ajax…)
- Why is admin ajax reloading my page
- Admin Ajax always return 0 on form submit
- Why this plugin doesn’t work with media upload page?
- Ajax call in wordpress not working for subscriber user in front site
- Solve cors problem using rest api or ajax
- Admin wp_ajax hook returning 0
- Why does WordPress Heartbeat login not refresh the nonces?
- Placement of add_action() for ajax callback?
- Identical wp_rest nonce returned from rest_api
- wp_handle_upload returns empty error array
- Loading comments in ajax – comment-reply function missing $args
- Woocommerce update product price via AJAX
- Enqueue script in plugin is not working
- Interim-Login form on frontend
- Ajax call does not work for this simple code
- Save value from Javascript object to WP user
- add Additional class to woocommerce cart-contents link
- Check ajax triggered from front-end or from dashboard
- Localize script not working
- How to Custom Edit Post Title & Permalink Slug?
- Add Ajax to rating button
- Why, if a function accepts arguments, it fails on ajax calls?
- How to disable drag-and-drop upload function in Media Library?
- Can’t retrieve any content from Ajax-loaded page
- adding ajax load more to display images from meta box
- Can’t load search results with ajax
- Change Post Meta via AJAX from the posts list table
- Ajax requests from front-end with jQuery Fancybox
- is there’s a way to get the next page content generated by page break block with ajax call?
- Passing value from select form with Ajax not working
- Sending email through Ajax without page refresh hangs on admin_ajax.php
- Is there a public ajax endpoint?
- Why Ajax Doesn’t Work?
- How can i do public ajax call?
- How to prevent multiple post with same meta value being created simultaneously in WordPress (with ajax)
- Frontend AJAX Media Upload returning 404
- Can’t GET Variable from AJAX URL
- How to update cart total after AJAX success
- How to implement AJAX within a class storing shortcode atts as class variables
- (Frontend AJAX) get post data WITH image thumbnail?
- AJAX Post from same domain to a wordpress page
- Ajax live search, “No products found” when the title contains apostrophes and quotations
- Add Ajax loaded posts to existing posts
- Change search to outpout category name instead of Post type name
- ‘Dehighlighting’ navigation once clicked
- Bad Request 400… jQuery ajax post of json data to wordpress admin-ajax.php
- At what stage does wp_ajax hooks gets applied during WordPress request?