• Resolved JP

    (@juanpa13)


    I’m trying to call the shortcode from an ajax request but some libraries appears to not loading , when i use the shortcode in the index.php works fine but when i use the ajax call the shortcode executes but the maps doesn’t show only the containers

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Matt Cromwell

    (@webdevmattcrom)

    I believe you’ll need to additional trigger the Google Maps Javascript after the AJAX call. This is an example of how you can trigger it again:
    https://github.com/WordImpress/Support-Snippets/blob/master/google-maps-builder/redraw-map.php

    Let me know how that goes.

    Thread Starter JP

    (@juanpa13)

    How should i implement this code, i’m not sure how to do it

    actually i have 3 parts of my code

    /* INDEX.PHP / TRIGGER ACTION*/
    <button class=”ver-mapa flex-it flex-align-item-center” data-shortcode=”42″><i class=”icon-location”></i>Ver en mapa</button>

    /* FUNCTIONS.PHP / AJAX CALL */
    add_action( ‘wp_ajax_show_map’, ‘show_map’);
    add_action( ‘wp_ajax_nopriv_show_map’, ‘show_map’);

    function show_map() {
    $short = ‘[google_maps id=”‘.$_REQUEST[‘shortcode’].'”]’;
    echo do_shortcode($short);
    die();
    }

    /* HEADER.PHP / DO AJAX CALL */
    $(‘.ver-mapa’).click(function(){
    var ajaxUrl = ‘<?php echo admin_url(‘admin-ajax.php’); ?>’;
    var data = {
    action: ‘show_map’,
    shortcode: $(this).attr(‘data-shortcode’)
    }
    $.post(ajaxUrl,data).done(function(response) {
    $(‘.lightbox-map’).show();
    $(‘.lightbox-map’).append(response);
    console.log(response);
    });
    });

    Plugin Author Matt Cromwell

    (@webdevmattcrom)

    It’s hard to say exactly, but the root of the problem is that our localized data isn’t being loaded because of your AJAX call. The plugin really isn’t built to be rendered that way. I’d recommend having the map on the page at load time and redrawing it when the lightbox initializes.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Do shortcode ajax call’ is closed to new replies.