javascript - Vegas and database issue

78

I have a problem withVegas.js. I'm trying to put images in from a database, but they are usually not displayed. Sometimes, only the first image is displayed once. However, if the images that I'm getting from the database are placed in a<img> tag, they are displayed properly, i also attached a screencap when i do a console.log of my JSON data. Here is my code :

//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; 

   



People are also looking for solutions of the problem: ftp_put(): can't open that file: no such file or directory
Source

Share


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.


Similar questions

Find the answer in similar questions on our website.

597 javascript - Vegas and database issue
715 html - Mysql Database Row values fetching issue in php
316 php - User input validation agains the database with javascript
391 php - Dynamically checking mySQL database to see if a currenttime has passed a datetime stored in the database
126 Viewing values in modal box/pop up - HTML, JavaScript, PHP and JavaScript
173 php - How to change array header and insert the array into MySQL database in PHPExcel?
623 javascript - Display alert message that's inside an action file, in another file
421 javascript - json works on localhost but not on server
47 javascript - Twitter Open Graph Dynamic images with only one URL
970 javascript - Wordpress JQuery not running for plugins

People are also looking for solutions to the problem: php - What can I do about exhausted memory on Wordpress while developing via a local Ubuntu server?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.