Answer the question
In order to leave comments, you need to log in
How to dynamically load html+js code and make it work?
Hello, I have the following problem: There are several pages that contain dynamic elements, eg gallery and slider (composed of html and js). When loading the content of these pages on a separate page via ajax (I use the axios library, loading events on button clicks, I click on one button - the 1st page is loaded, on the 2nd - another) the resulting page is almost correctly displayed (html and css code pages), I get and output something like this:
$pageBlock = document.getElementById('content');
axios.get(this.elementUrl {
responseType: 'json'
}).then((response) => {
this.pageBlockContent = response.data;
$pageBlock.innerHTML = this.pageBlockContent;
Answer the question
In order to leave comments, you need to log in
When loading
For these purposes - I created includeHTML (for SPA and other interactive web applications).
It just allows you to download (and check whether it has already been loaded) the necessary HTML blocks and JS scripts (+ CSS and TXT).
All description is on github. It is not clear - ask: I will answer.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question