updated 10th Jan 2018 Write a javascript function to trigger the ajax call
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | jQuery('#button_or_something').on("click", function() { jQuery.ajax({ url: ajax_object.ajax_url, data: { action: 'like_or_not', /* this is appended to add_action on server side */ id: '99' }, type: 'GET', success:function(response){ //alert('back from ajaxe '+response); /* if you want to update something based on the response text */ jQuery('#gb_div_to_update').html(response); } }); }); |
Put js above in my_js_file.js (see later in this post). Wrap in code below for nice loading: jQuery( document ).ready(function() { put above code here }); To see how to send a form via ajax see here. Write a … Read more