Vegas和数据库问题

时间:2018-01-26 10:41:13

标签: javascript php json vegasjs

我对Vegas.js有疑问。我试图从数据库中放入图像,但通常不显示它们。有时,只显示第一个图像一次。但是,如果我从数据库中获取的图像放在<img>标记中,它们会正确显示,当我执行我的JSON数据的console.log时,我还附加了一个screencap。这是我的代码:

&#13;
&#13;
//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;
&#13;
&#13;

如果有人可以帮助我或让我知道我做错了什么,我们将不胜感激。

提前致谢。以下是控制台日志的屏幕截图:JSON data console.log

0 个答案:

没有答案