yii2 在 GET 方法中隐藏来自 url 的模型名称

yii2 hide model name from url in GET Method

我有一个脚本可以在一定时间内切换图像。但是在我的页面上,图像没有显示,因为它们获取方法错误 URL: GET http://schedule/monitor/img/math/22.03/22.03.JPG 404(未找到)。正确的 URL 应该是这样的: http://schedule/img/math/22.03/22.03.JPG。当我从 js 脚本中获取模型名称时,如何从图像 src 中隐藏模型名称?

slider.js

    $(document).ready(function () {
    $.ajax({
        type: 'GET',
        dataType: 'json',
        url: '/monitor/insert_math',
        data: 'json',
        success: function (data) {

            var i = 0;          //START POINT
            var unfiltered_images = data;   //UNFILTERED IMAGES ARRAY
            var time = 30000;   //TIME BETWEEN SWITCH

            var images = unfiltered_images.filter(file => file.endsWith('.JPG')); //FILE FILTER BY EXTENSION
            console.log(images);

            if (images.length != 0) {

                function changeImg() {

                    document.getElementById('slide').src = images[i];

                    if (i < images.length - 1) { //CHECK IF INDEX IS UNDER MAX
                        i++; //ADD 1 TO INDEX
                    } else {
                        i = 0; //RESET BACK TO 0
                    }
                    setTimeout(changeImg, time); //RUN FUNCTION EVERY X SECONDS
                }

                window.onload = changeImg(); //RUN FUNCTION WHEN PAGE LOADS
            }
        }
    });
});

1311.php

<div class="info_block">
      <img id="slide" height="626px">
</div>

PHP 文件的路径:

document.getElementById('slide').src = "/"+images[i];

Shringiraj Dewangan

回答