JQuery浏览器控制台错误消息

时间:2017-08-02 16:13:33

标签: javascript jquery json

我正在尝试通过JSON显示图像名称来自MySQL查询的图像。

我的JSON:

[{"data":[{"ClientImageName":"1_logo.png","ClientName":"Name","RoomName":"Room 2","RoomFromTime":"06:00","RoomToTime":"17:00"},{"ClientImageName":"1_logo.png","ClientName":"Name","RoomName":"Room 6","RoomFromTime":"06:00","RoomToTime":"23:00"},{"ClientImageName":"1_logo.png","ClientName":"Name","RoomName":"Room 1","RoomFromTime":"07:00","RoomToTime":"17:00"},{"ClientImageName":"1_logo.png","ClientName":"Name","RoomName":"Room 18","RoomFromTime":"07:00","RoomToTime":"23:00"}]}]

读取数据的jQuery是:

$(document).ready(function() {
    function get_data() {
        $.getJSON("get_data_logos.php", function(json){
            json = json[0].data;
            var tr ;

            for (var i = 0; i < json.length; i++) {
                tr = $('<tr/>');
                tr.css("border-bottom","2px solid #FFF");
                tr.append("<td width='33%'><div class='clientimage-text'><img src='../../../../conf_images/boards/'" + json[i].ClientImageName + "></></div></td>");
                tr.append("<td width='33%'><div class='clientname-text'>" + json[i].ClientName + "</div></td>");
                tr.append("<td width='33%'><div class='roomname-text'>" + json[i].RoomName + "</div></td>");
                tr.append("<td width='33%'><div class='time-text'>" + json[i].RoomFromTime + " - " + json[i].RoomToTime + "</div></td>");
                $('table').append(tr);
            }
        });
    }
    get_data();
    setInterval(get_data,60000)
});

包含图片的行是:

 tr.append("<td width='33%'><div class='clientimage-text'><img src='../../../../conf_images/boards/'" + json[i].ClientImageName + "></></div></td>");

当我运行脚本时,只显示图像的占位符。当我查看控制台时,我看到以下消息“您无权访问/ apps / conf / conf_images / boards / 在这台服务器上。“

如果我对图像名称进行硬编码,则可以正常工作。

我的问题是我是否正确编写了关于代码行的JQuery:

tr.append("<td width='33%'><div class='clientimage-text'><img src='../../../../conf_images/boards/'" + json[i].ClientImageName + "></></div></td>");

如果我检查代码行,我会看到:

<img src="../../../../conf_images-boards/" 1_logo.png=""> 

它应该是

<img src="../../../../conf_images-boards/1_logo.png>.

1 个答案:

答案 0 :(得分:2)

这一行:

tr.append("<td width='33%'><div class='clientimage-text'><img src='../../../../conf_images/boards/'" + json[i].ClientImageName + "></></div></td>");

报价不正确。你想要:

tr.append("<td width='33%'><div class='clientimage-text'><img src='../../../../conf_images/boards/" + json[i].ClientImageName + "'></></div></td>");