0

I have this script <script type="text/javascript" src="customJS/jsonRetrieve.js" async></script>

The script makes me retrieve the data from a JSON file and store it in an array.

first question is: how can i load my index page only after the script is fully loaded? i get the error of 'undefined'.

After loading the script i have to add the code from the array something like this

"<img src='images2/1.jpg' id='0' style='width:70%' class='rounded' data-toggle='modal' onclick='setMod(this.id);setData(this.id)' data-target='#myModal' />"

to my carousel and that by adding it to the div. I used the jQuery function 'append' to add the images to my #carousel div but the images are not showing in the carousel preview. how can i fix that ? should i refresh the carousel ?

<script type="text/javascript" src="js/jquery.waterwheelCarousel.js" defer></script>
<script type="text/javascript" src="customJS/carouselJS.js" defer></script>
$(window).load(function () {
 $('#carousel').append(items[0]);
});
Andrew L
5,5161 gold badge29 silver badges40 bronze badges
asked May 9, 2018 at 17:29
7
  • 1
    Can you provide a minimal verifiable example with a working snippet? Commented May 9, 2018 at 17:35
  • You would ideally need to refresh the carousel after adding the images dynamically. Commented May 9, 2018 at 17:35
  • @Studocwho how can i refresh the carousel scripts and css and the div Commented May 9, 2018 at 17:45
  • @CalvinNunes thats alot of work x) Commented May 9, 2018 at 17:45
  • cant i make the carousel to load only after i added the images dynamically ? Commented May 9, 2018 at 17:47

1 Answer 1

1

You can prevent a script from loading until you add the images with something like this:

<script onload="customJsFunction();" src ="customJS/jsonRetrieve.js"></script>

A similar question is here: Call javascript function after script is loaded.

answered May 9, 2018 at 19:48
Sign up to request clarification or add additional context in comments.

4 Comments

Could you you setup a fiddle here: jsfiddle.net It'll help everyone read and test your code.
i think i have to load this script <script type="text/javascript" src="js/jquery.waterwheelCarousel.js" ></script> after i add the images
any solution ? i couldnt find a way to make this work
Thanks for making a fiddle. The issue is with $('#carousel').append(items[0]);. items isn't an array defined in that function! You need to return the value of jsonRetrieve.js not just include the file. Please check out line 43 jsfiddle.net/j4pruxs5/1

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.