我对Vegas.js
有疑问。我试图从数据库中放入图像,但通常不显示它们。有时,只显示第一个图像一次。但是,如果我从数据库中获取的图像放在<img>
标记中,它们会正确显示,当我执行我的JSON数据的console.log时,我还附加了一个screencap。这是我的代码:
//JS
$.getJSON('ajax/Slides.php', function(slide) {
$.each(slide, function(i,slides) {
$('#slideMain').vegas (
{ slides: [{src: slides["path"]}] }
);
})
});
//However, if I do something like this, it shows me all the images:
$('#slideMain').append('<img src="'+slide+'">');
&#13;
// PHP
#I have 3 columns in the DB(id,path,order),
#but i only need the path
#conexion to the database
public function showSlideModel($table)
{
$stmt = conexion::connect()->prepare("SELECT path FROM $table ORDER BY order ASC");
$stmt -> execute();
return $stmt -> fetchAll();
$stmt -> close();
}
#this is the controller
public function SlideController()
{
$answer = SlideModel::showSlideModel("slides");
foreach($answer as $row => $item)
{
$slides[] = array('path'=>substr($item["path"], 6));
}
$jsonSlide = json_encode($slides);
echo $jsonSlide;
}
// Ajax
$slide = new Slider();
$slide ->SlideController();
echo $slide;
&#13;
如果有人可以帮助我或让我知道我做错了什么,我们将不胜感激。
提前致谢。以下是控制台日志的屏幕截图: