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
- Blocking admin-ajax.php from outside domain
- wp-admin/admin-ajax.php 400 Bad request (chrome console)
- contact form 7 form not working in admin panel
- How does the security of admin_ajax.php work?
- PHP “php://input” vs $_POST
- Google Maps API throws “Uncaught ReferenceError: google is not defined” only when using AJAX
- Access-Control-Allow-Origin error sending a jQuery Post to Google API’s
- Access-Control-Allow-Origin error sending a jQuery Post to Google API’s
- How to solve the error “SCRIPT7002: XMLHttpRequest: Network Error 0x80070005, Access is denied.” in IE
- Show spinner GIF during an $http request in AngularJS?
- Refresh HTML Page in Browser Automatically on Timer – Every 15 Min
- JavaScript implementation of Gzip
- jQuery: Performing synchronous AJAX requests
- ASP.NET MVC controller actions that return JSON or partial html
- jQuery’s .on() method combined with the submit event
- Ajax takes 10x as long as it should/could
- How to check if I am in admin-ajax.php?
- Best way to end WordPress ajax request and why?
- How to load wp_editor() through AJAX/jQuery
- How to cache json with wp-super cache
- Load minimum WordPress environment
- Why use wp_send_json() over echo json_encode()?
- Why use admin-ajax.php and how does it work?
- How to get a unique nonce for each Ajax request?
- Open a Thickbox with content trough AJAX
- Initialize TinyMCE editor / visual editor after AJAX insert
- Admin ajax request return 0 with die()
- Why not register shortcodes if is_admin dashboard?
- WordPress AJAX with Axios
- Why is die() used at the end of function that handles an Ajax request?
- Why might a plugin’s ‘do_shortcode’ not work in an AJAX request?
- Making my AJAX powered WordPress Crawlable
- Is there a JavaScript API? How to access public and private data in JS?
- Get Previous & Next posts by Post ID
- failed to load wp-admin/admin-ajax.php
- Using Backbone with the WordPress AJAX API
- Using Ajax with a Class file
- Ajax in a settings page (update_option is undefined)
- How to pass data parameter to ajax action function handler
- WordPress Ajax Data Security
- Displaying PHP Errors from admin-ajax.php
- wp_set_auth_cookie() doesn’t work in Ajax call
- gettext does not translate when called in ajax
- Execute one AJAX request after another AJAX request finished
- Custom column for changing post status via ajax
- WP-AJAX vs WP REST API: What to use for requests to the website from outside?
- Ajax and autocomplete
- How to add to cart via AJAX Woocommerce [closed]
- Nonces and Cache
- WordPress 4.8: Using multiple WYSIWYG-Editors with media inside of Widgets how to?
- SSL breaks customizer: page isn’t returned from ajax
- Why is a 500 error generated by admin-ajax.php not going into the Apache error log?
- Are ‘wp_ajax’ and ‘wp_ajax_nopriv’ exclusive to authenticated and non-authenticated users?
- How to HTML5 FormData Ajax
- admin-ajax.php vs Custom Page Template for Ajax Requests
- How to override WP_DEBUG for Ajax responses?