First, you need to output a response in your my_action_callback()
function. That response will be available inside your jQuery success callback: function(response){}
. At that point it is just a matter of updating the HTML of the page with the new views count.
PHP:
function my_action_callback()
{
// ...
echo $views;
exit;
}
JavaScript:
jQuery.post(ajaxurl, data, function(response) {
// $(this) refers to the clicked link.
// You may use another selector too if needed.
$(this).text(response);
});
Related Posts:
- How to populate custom field dropdown box based on prior selection?
- Trying to implement AJAX into my admin pages. Am I improperly enqueue and localizing my scripts?
- Get custom fields when hover link of post
- Validating Custom Meta Box Values & Required Fields
- Add a Jquery Datepicker to custom field in post edit
- Arrange custom fields with drag and drop?
- Convert jQuery Datepicker Format to SQL Date Format
- Edit Custom Database Tables in WordPress
- Fetch and show multiple custom fields via AJAX
- Register new user and add custom data row value for it
- Update WordPress Custom Field with AJAX on cached page
- Update meta values with AJAX
- Front-end update_post_meta with ajax
- making sense of admin-ajax
- sort search results by custom fields using dropdown
- How do I use Ajax to build a dropdown of custom fields based on a post selected in previous dropdown?
- Update Custom post field by Ajax on cached site
- load custom fields on click
- WordPress: custom field display twice
- jQuery – Automatic event trigger does not **really** check my form
- Adding auto-complete to custom gravity field not working
- Uploading PDF using Media Uploader
- Show user info in a hovercard [closed]
- Get image url using image id
- How to use media upload on metabox post page without breaking TinyMCE?
- WordPress colorpicker save both hex and RGB
- Add a counter for mouseovers (custom field)
- How do I convert all custom_field php timestamps in the database to js timestamps?
- Jquery on custom-field backend
- Custom field bug in WordPress 3.2
- Meta field bulk editing no longer working in WP 6.0 [closed]
- Populate Product Regular Price with a calculated ACF Field Value
- Add forms dynamically in admin pages?
- How can I create a button that when clicked populates a div with a list of foods that are checked as a certain type of ACF?
- How to save multiple custom user profile fields using repeater JQuery
- create a custom field that let me include other posts
- Get a different meta value with ajax when different elements are clicked
- change attachment custom field onChange event
- CSS conditional on custom field value
- Validating custom meta boxes with jQuery results in posts being saved as draft instead of published post
- show custom field content in jquery tabs
- Output custom field as ul list
- WP_query multiple custom fields not working
- Single page WordPress website – custom fields or meta boxes or something else?
- Custom field Search with Relavanssi
- Collect Data from NEXT item while in loop
- Order custom fields alphabetically
- Retrieving custom field value with get_post?
- How to exclude custom fields from search queries?
- Is there some jQuery conflict here?
- Add Custom Fields After Page Title
- Custom Theme Fields in Settings Menu – apply filters to one of those fields?
- KEY and VALUE custom field issue
- Footnotes in custom fields
- Custom metabox not working
- Run Function if Order Meta Exists – WooCommerce
- Image upload and path to custom field
- Help with this custom field conditional if no field is set display nothing
- Custom wpdb query – how to sort post by another table meta_count
- How to change permalink on headlines in rss feeds?
- if statement display content even though no data
- How to get custom image field of specific post id
- Create a new custom field for all posts based on current custom field
- Listing the most popular 8 city (custom fields) as used in posts
- Display latest post depending on Meta Box content
- How to delete file uploaded by Plupload
- How to pass custom field value to shortcode?
- Display Meta Data with HTML?
- How to use wp_update_post with ajax on frontend
- Automatic linking terms
- custom comment_form fields not displaying
- Custom field to array?
- Fallback for empty custom fields
- WP_Query () using taxonomy, custom post types
- WP-eComerce Advance Meta Tag data in descending order [closed]
- Adding extra fields to front end signup form
- Problem uploading different files as custom fields with front end post form
- Using jQuery .after inside loop
- How to change order of posts in admin
- How to store meta field values
- How to sort by custom field value?
- Using AJAX to run SQL statement and populate dropdown
- Display custom field value as a mailto: link
- Meta Box Plugin Cloned Fields – Multiple Foreach values
- Ordering by ‘Title’ OR ‘Custom Field’
- How can I add/update post meta in a admin menu page?
- Getting jQuery AJAX to work in WordPress (getting -1)
- Custom product fields in wp e-Commerce plugin [closed]
- problems with jquery external rss feed integration
- wp_editor on custom meta textarea field – images and html fails
- pull all posts’ meta key values from current category only
- Converting a working AJAX form to work with WordPress
- Show array of meta_value in Edit Post Coloum
- Custom Query Fields – Altering Meta Value
- Is it possible to use get_post_meta() to control HTML?
- Editing custom fields for comments
- using custom fields on content.php file of my theme
- get_post_meta returns 0
- what does $options = get_option(‘test_theme’); do?
- Connect Agile Carousel to WordPress AJAX