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
- Can I count the number of users matching a value in a multiple value key?
- jQuery and AJAX Not working with Select Form Element
- How to delete custom field “suggestions” from dropdown list
- How to load php file for specific page in admin?
- How to set default metaboxes on user creation?
- custom field with total count of Facebook likes, comments and shares
- How to show custom field’s value under post/page title in wp-admin
- Query on custom field count?
- Transition from (classical) serialized custom meta field to (gutenberg) rest enabled meta
- WordPress AJAX Call Not Return Result
- Unable to show ACF’s Image Custom Field properly in Genesis Framework [closed]
- How to display something in a div when the user clicks on a text in another div – no page refresh [closed]
- Delete all custom fields at once?
- Sorting posts ordered by custom field value
- Odd PHP Code To Display HTML Of Meta Box [closed]
- strtotime and custom field value
- Unique Post Meta Values
- WP 3.1 meta_query for multiple custom field values
- Better way to save image in custom field
- Jetpack post types Portfolio or Testimonials support for custom fields?
- Merge Multiple Custom Fields into one New Custom Field for Searching
- Is there a better way to list all database terms alphabetically?
- Retrieve post info within AJAX helper function
- Select multiple images from custom field
- Unique meta_key with array value vs repeated meta_key with single values
- Allow only one post with specific meta value
- Querying posts by latitude and longitude to build a Google Maps with several markers
- How to display childrens custom fields?
- Attach images to posts using custom fields (just paths to images already uploaded)
- how to display custom fields of post on a web page
- How to keep track of when a vote is cast?
- Changed PHP handler to DSO – weird custom fields problem [closed]
- How to fill custom fields with brackets in their key with add_post_meta()?
- How to use a dropdown to filter posts by custom field
- Front-End User Profile
- How to retrieve WP_Object that is inside an array of another array
- put saved metabox values back into fields and then display on the front end
- Custom field to array?
- How to sort by custom field value?
- How to query posts by month based on date custom field?
- Change word in woocommerce product category custom field
- get posts based on non-single metadata
- Problem with revisions only returning four results
- How to save multiple values with same meta_key, each value linked to another tag id
- How to use wp_ajax_set_post_thumbnail?
- What WordPress “technology” would I use if I wanted subscribers to be able to mark pages with characteristics and notes?
- how can i show WordPress custom field data to my short code?
- searching by keywords in post’s metas or pagination links problem
- Permanently show Custom Fields in Editor
- open modal window
- a lot of custom fields
- Hide custom fields by user’s role
- update meta field value after
- If metabox fields has content display content
- Custom fields and auto save
- Save values generated via API as custom meta fields
- Load code for custom fields only on admin pages?
- Exclude empty fields from custom field calculation (Average)
- Match submitted array fields with the MYSQL database fields to update them correctly in PHP