const newDiv = document.createElement("div"); newDiv.setAttribute('class','row calendar'); newDiv.setAttribute('id','calendar-container'); const script = document.getElementById("sr-calendar"); script.parentNode.insertBefore(newDiv,script); const bookable_id = script.getAttribute('data-bookable-id'); const auth = script.getAttribute('data-auth'); const url_base = 'https://sr-channel.es/api/get-calendars/'; loadCalendar(url_base+bookable_id); function loadCalendar(url){ document.getElementById("calendar-container").innerHTML = 'Cargando ..'; if (window.XMLHttpRequest){ var xhReq = new XMLHttpRequest(); }else{ var xhReq = new ActiveXObject("Microsoft.XMLHTTP"); } xhReq.open('GET', url, false); xhReq.setRequestHeader("X-Requested-With", "XMLHttpRequest"); xhReq.setRequestHeader('Authorization', 'Bearer '+auth); xhReq.send(null); document.getElementById("calendar-container").innerHTML = xhReq.responseText; document.getElementById('btn-prev').onclick=function(){ document.getElementById("calendar-container").innerHTML ='Cargando ...'; var type = this.getAttribute('data-type'); var id = this.getAttribute("data-id"); var month = this.getAttribute('data-prev-month'); var year = this.getAttribute('data-prev-year'); loadCalendar(url_base+id+'/'+year+'/'+month); } document.getElementById('btn-next').onclick=function(){ document.getElementById("calendar-container").innerHTML ='Cargando ...'; var type = this.getAttribute('data-type'); var id = this.getAttribute("data-id"); var month = this.getAttribute('data-next-month'); var year = this.getAttribute('data-next-year'); loadCalendar(url_base+id+'/'+year+'/'+month); } }