You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi. I am trying to lazy load a Divi shortcode from library using AJAX, but the only output I get in the page is
[et_pb_section global_module="16594"][/et_pb_section]
Steps To Reproduce
In child theme functions.php I am using this code: function load_lazy_shortcode_content() {
if (isset($_GET['global_module'])) {
$global_module_id = intval($_GET['global_module']);
$shortcode = '[et_pb_section global_module="' . $global_module_id . '"][/et_pb_section]';
echo do_shortcode($shortcode);
}
wp_die();
}
add_action('wp_ajax_load_lazy_shortcode_content', 'load_lazy_shortcode_content');
add_action('wp_ajax_nopriv_load_lazy_shortcode_content', 'load_lazy_shortcode_content');
In builder, this javascript to handle AJAX calling
<script async>
document.addEventListener("DOMContentLoaded", function () {
const lazyListContainer = document.getElementById("lazyListContainer");
let divLoaded = false;
function loadDiv() {
const rect = lazyListContainer.getBoundingClientRect();
const windowHeight = window.innerHeight || document.documentElement.clientHeight;
if (rect.top < windowHeight && rect.bottom > 0 && !divLoaded) {
divLoaded = true; // Marca que el div ya ha sido cargado
const xhr = new XMLHttpRequest();
xhr.open("GET", "/wp-admin/admin-ajax.php?action=load_lazy_shortcode_content&global_module=16594", true);
xhr.onload = function () {
if (xhr.status === 200) {
const lazyDiv = document.createElement("div");
lazyDiv.classList.add("lista-lazy-loaded");
lazyDiv.innerHTML = xhr.responseText; // Inserta el contenido HTML del shortcode procesado
lazyListContainer.appendChild(lazyDiv);
}
};
xhr.send();
window.removeEventListener("scroll", loadDiv);
}
}
window.addEventListener("scroll", loadDiv);
loadDiv();
});
</script>
All i get in the frontend is this: [et_pb_section global_module="16594"][/et_pb_section]
What am I doing wrong? Thanks.
The text was updated successfully, but these errors were encountered:
Hi. I am trying to lazy load a Divi shortcode from library using AJAX, but the only output I get in the page is
[et_pb_section global_module="16594"][/et_pb_section]
Steps To Reproduce
In child theme functions.php I am using this code: function load_lazy_shortcode_content() {
if (isset($_GET['global_module'])) {
$global_module_id = intval($_GET['global_module']);
$shortcode = '[et_pb_section global_module="' . $global_module_id . '"][/et_pb_section]';
echo do_shortcode($shortcode);
}
wp_die();
}
add_action('wp_ajax_load_lazy_shortcode_content', 'load_lazy_shortcode_content');
add_action('wp_ajax_nopriv_load_lazy_shortcode_content', 'load_lazy_shortcode_content');
In builder, this javascript to handle AJAX calling
What am I doing wrong? Thanks.
The text was updated successfully, but these errors were encountered: