Display Elementor template through Ajax

  ajax, elementor, javascript, php

I’m trying to display the Media Carousel widget of Elementor dynamically through Ajax.

So, this is my PHP code:

ob_start();
echo do_shortcode('[elementor-template id="3057"]');
$response['content'] = ob_get_contents();
ob_end_clean();
die(wp_json_encode($response));

And my js code:

$.ajax({
    url : ajaxaction.ajax_url,
    type : "post",
    dataType : "json",
    data : {
        action          : "ajax_action",
        action_case     : aj_action_case,
        action_data     : aj_action_data,
    },
    success : function( response ) {
        if ( response.content ) {
            $("#product-main").html(response.content);
            
        }
        ...

In this way I get the media carousel inside my container but of course it’s not working because missing the Javascript of the widget.

Is there a way to hook the Javascript of the Elementor widget in my ajax callback?

Or maybe is there a better way to do this…?

Source: Ask PHP

LEAVE A COMMENT