تنفيذ جافا سكريبت في كتلة الشريط الجانبي المخصص HTML

I am using a custom-html block with content:

<div id="server-01-box"></div>
<script>
    fetch('//example.com/wp-admin/admin-ajax.php?action=aa-server-select&p=server-01')
        .then(function (response) {
            return response.text();
        })
        .then(function (body) {

            var server_parser = new DOMParser();
            var doc = server_parser.parseFromString(body, "text/html");
            var ad_container = doc.querySelector('div');

            document.querySelector('#server-01-box').innerHTML = ad_container.innerHTML;
        });
</script>

When I inspect the page HTML, its injected there. However, my ad doesn’t show up. Is there a trick to getting the JS to run from within the sideblock plugin?

إعجاب واحد (1)

I had to make a different custom theme component to get the JS to run, which is fine. Closing this out.

إعجابَين (2)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.