Answer the question
In order to leave comments, you need to log in
How to implement ajax loading of goods on pure js?
For example, the page is loaded first, and a request is made to the server, and objects are inserted into the wrapper:
document.getElementsByClassName('wrapper')[0].innerHTML = this.responseText;
document.getElementsByClassName('wrapper')[0].innerHTML = document.getElementsByClassName('wrapper')[0].innerHTML + this.responseText;
document.getElementsByClassName('wrapper')[0].innerHTML + this.responseText;
Answer the question
In order to leave comments, you need to log in
Slowly, very, so it will be faster:
const helper = document.createElement('div');
const wrapper = document.querySelector('.wrapper');
helper.innerHTML = this.responseText;
wrapper.appendChild(helper);
// Если нужно без лишнего div
let child;
let frag = document.createDocumentFragment()
while (child = helper.firstChild) {
frag.appendChild(child);
}
wrapper.appendChild(frag);
Quite normal practice.
If there are a lot of inserts, you need to use documentFragment for optimization
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question