我有一个问题Vegas.js
。我正在尝试从数据库中放入图像,但通常不会显示它们。有时,只显示第一张图像一次。但是,如果我从数据库中获取的图像放置在<img>
标签中,它们会正确显示,当我对 JSON 数据执行 console.log 时,我还附加了一个屏幕截图。这是我的代码:
//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+'">');
// 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;
如果有人可以帮助我或让我知道我做错了什么,将不胜感激。
提前致谢。这是控制台日志的屏幕截图: