我想顯示圖像,其中圖像名稱來自通過JSON的MySQL查詢。JQuery瀏覽器控制檯錯誤消息
我的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>.
嗨,你嘗試更改權限文件夾conf_images /板/與'chmod 755'? –
@Guillermo Andres Fuentes道德嗨,他們已經是755.甚至嘗試過777沒有喜悅。正如我所說,如果我硬編碼從相同的文件夾中的圖像名稱,它工作正常。但是因爲圖像名稱是動態的,所以它需要是來自Json的變量名稱。 – DCJones
你試着爲控制檯打印這個'json [i] .ClientImageName'並檢查你的相對路徑是否正常,我相信你的相對路徑可以挑釁這個錯誤 –