paolo_bortolotti

ajax

Jun 4th, 2021 (edited)
33
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. JS:
  2.  
  3. jQuery(document).ready(function($){
  4. jQuery('.mappa').each(function() {
  5. jQuery(this).magnificPopup({
  6. delegate: 'a',
  7. type: 'inline',
  8. midClick: true
  9. });
  10. });
  11.  
  12. jQuery('.mappa a').click(function(){
  13. // alert("The id is "+ jQuery(this).attr("data-id") );
  14. var post_id = jQuery(this).attr("data-name");
  15.  
  16. jQuery.post(
  17. ajaxurl,
  18. {
  19. 'action': 'load_post_content',
  20. 'the_ID': post_id
  21. },
  22. function(response){
  23. jQuery('#opencomune span').html(response);
  24. }
  25. );
  26. return false;
  27. });
  28. });
  29.  
  30.  
  31. FUNCTION:
  32.  
  33. add_action( 'wp_ajax_load_post_content', 'load_post_content' );
  34. add_action( 'wp_ajax_nopriv_load_post_content', 'load_post_content' );
  35.  
  36. function load_post_content() {
  37.  
  38. $the_post_id = $_POST['the_ID'];
  39. echo $the_post_id;
  40.  
  41. }
  42.  
  43.  
  44. PAGINA PHP
  45. load_post_content();
  46.  
  47.  
  48.  
  49.  
  50.  
RAW Paste Data