0

The images are stored inside separate folders.

Both the folders and the images are saved in the database. In my gallery page, they are shown from the database in two steps.

  1. The folders are retrieved from the db and listed in the gallery page
  2. while on-click of a folder, the images are to be listed. So far, I have passed the data from the database to the view and i have passed the foldernameto the ajax-call using onclick function

and my view code is as follows:

 <?php foreach($folder_info as $show){ ?>
<a class="glyphicon glyphicon-folder-close" style="font-size: 100px;" aria-hidden="true" onclick="imageslide('<?php echo $show['folder_id'] ?>');" ></a>
 <?php } ?>

Presently, I am not able to retrieve the passed $show['folder_id'] inside the <script> My ajax call is as follows:-

<script>

function imageslide(folderid){
alert(folderid);

$.ajax({
    url: "<?php echo site_url() ?>/welcome/getall_images",
    type: "GET",
    dataType: "json",
    data: {'id': folderid},
    success: function(data) {

        alert(data);
    }
}); </script>
4
  • Do like this, data : { id: folderid }, Commented May 23, 2017 at 5:44
  • what is the difference b/w 'id' & id..?I tried using it but i did not get it.. Commented May 23, 2017 at 5:47
  • Data should be PlainObject or String or Array, you have passed wrong format. You can check here AJAX @Keynes Commented May 23, 2017 at 5:53
  • Are you getting folderid inside function imageslide? Commented May 23, 2017 at 6:00

1 Answer 1

1

Ajax Script

$.ajax({
    url: "<?php echo site_url() ?>/welcome/getall_images",
    type: "POST",
    dataType: "json",
    data: {id: folderid},
    success: function(data) {

        alert(data);
    }
}); </script>

Controller Code

function getall_images(){
   $folderId = $this->input->post('id');
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.