2017-08-02 59 views
0

我想显示图像,其中图像名称来自通过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>. 
+0

嗨,你尝试更改权限文件夹conf_images /板/与'chmod 755'? –

+0

@Guillermo Andres Fuentes道德嗨,他们已经是755.甚至尝试过777没有喜悦。正如我所说,如果我硬编码从相同的文件夹中的图像名称,它工作正常。但是因为图像名称是动态的,所以它需要是来自Json的变量名称。 – DCJones

+0

你试着为控制台打印这个'json [i] .ClientImageName'并检查你的相对路径是否正常,我相信你的相对路径可以挑衅这个错误 –

回答

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>"); 
+1

井点。我一直在看这个好几个小时。 – DCJones

+0

干杯,它发生在我们所有人身上! – wmorrell