简体   繁体   English

是否可以将SSI插入PHP文件中的javascript中?

[英]Is it possible to insert SSI into javascript in a PHP file?

As I don't know javascript at all, I'm wondering if it's possible to insert some SSI into javascript in a PHP file. 因为我根本不了解javascript,所以我想知道是否可以在PHP文件的javascript中插入一些SSI。 I've got a bit of script going to preload some images, and I'd like to set it up so that some images always get preloaded across my entire site (via the SSI) of which I may add to over time, while allowing me to add individual images as needed page by page. 我有一些脚本可以预加载一些图像,并且我想对其进行设置,以便始终在我的整个站点(通过SSI)上预加载一些图像,随着时间的推移我可能会添加到其中,同时允许我可以根据需要逐页添加单个图像。 It works fine in my HTML files, but not it my PHP files. 它可以在我的HTML文件中正常运行,但不能在我的PHP文件中运行。

Here's what I've got in my HTML files which works just fine: 这是我在HTML文件中可以正常运行的内容:

<script>
    function preload(arrayOfImages) {
        $(arrayOfImages).each(function () {
            $('<img/>')[0].src = this;
        });
    }
    preload([
        <!--#include virtual="/grabbag/preload-images.html" -->
        '/images/image-1.png',
        '/images/image-2.png'
    ]);
</script>

But this doesn't work in my PHP files, the SSI getting replaced with nothing but empty text: 但这在我的PHP文件中不起作用,SSI被空文本代替:

<script>
    function preload(arrayOfImages) {
        $(arrayOfImages).each(function () {
            $('<img/>')[0].src = this;
        });
    }
    preload([
        <?php include("/grabbag/preload-images.php"); ?>
        '/images/image-1.png',
        '/images/image-2.png'
    ]);
</script>

Is this possible? 这可能吗? Thanks in advance. 提前致谢。

Your PHP include is absolute. 您的PHP包含是绝对的。 It begins with a / and therefore it'll look in the root (the up most path) and tries to traverse down. 它以/开头,因此它将在根(最上方的路径)中查找并尝试向下移动。 Change it to a relative one or the correct absolute one and a it'll work 😉 将其更改为相对值或正确的绝对值一个,它将起作用😉

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM