Hello. The topic is very hackneyed, but I could not find an answer. Everyone knows that after uploading AJAX data, the rest of the scripts will not be executed. It is necessary to initialize them through success, ajaxComplete, etc. But I have never found a solution for native javascript anywhere. All solutions concern jQuery! It so happened that part of the code (photo gallery) was written in native javascript. I think there is no need to upload all the code. Scroll through the photos like this:
var gallery = new Gallery(sources); Array.prototype.forEach.call(links, function(link, index) { link.onclick = function() { gallery.show(index); }; }); How do I make this code work? The success, ajaxComplete methods are only suitable for jQuery. Perhaps, try to bind the code above to jQuery, but I don’t know how to do this.
Duck Learns Mind - you are right. You need to add a call code.
var WORKS_METHOD ={ handlerData:function(resJSON){ var templateSource = $("#works-template").html(), template = Handlebars.compile(templateSource), worksHTML = template(resJSON); $('#works-container').html(worksHTML); }, loadWorksData : function(){ $.ajax({ url:"https://path/to/worksdata.json", method:'get', success:this.handlerData }) } }; $(document).ready(function(){ WORKS_METHOD.loadWorksData(); }); AJAX call loads thumbnails of photos, on click on which this gallery is called. Do you suggest rewriting the call to xmlHTTPRequest?