rDrama/files/assets/js/viewmore.js
2021-12-05 20:15:41 -06:00

21 lines
No EOL
863 B
JavaScript

function loadMore(pid,sort,offset,id,trigger) {
const btn = document.getElementById(trigger) // trigger button
const el = document.getElementById(id) // target element to populate
const form = new FormData();
const xhr = new XMLHttpRequest();
btn.classList.toggle('animate-pulse');
xhr.open("post", `/viewmore/${pid}/${sort}/${offset}`);
xhr.withCredentials=true;
xhr.onload=function(){
if (xhr.status==200) {
el.innerHTML = xhr.response.replace(/data-src/g, 'src').replace(/data-cfsrc/g, 'src').replace(/style="display:none;visibility:hidden;"/g, ''); // replace desired element with response html
btn.style.display = "none"; // hide button
initializeBootstrap()
} else {
btn.disabled = false; // enable our button if GET fails
}
}
xhr.send(form)
}