JSFiddle - React, Tailwind, and code Playground
by jpeter06
HTML
<button onclick="pedirDatos()">
PEdir datos
</button>
<button onclick="pedirDatos2()">
PEdir datos2
</button>
<script async="" src="https://demanda.ree.es/WSvisionaMovilesPeninsulaRest/resources/demandaGeneracionPeninsula?callback=showData&curva=DEMANDAQH&fecha=2022-12-2"></script>
JavaScript
let demandaReq = 'https://demanda.ree.es/WSvisionaMovilesPeninsulaRest/resources/demandaGeneracionPeninsula?callback=angular.callbacks._7&curva=DEMANDAQH&fecha=2022-12-2';
function pedirDatos(){
fetch(demandaReq).then(function(response) {
console.log(response.text());
}).then(function(text) {
console.log(text.substring(0, 30));
});
}
function pedirDatos2(){
fetch(demandaReq)
.then(response => response.text())
.then(txt => eval(txt))
.then(() => {
document.getElementById('status').innerHTML = 'moment.min.js loaded'
// now you can use the script
document.getElementById('today').innerHTML = moment().format('dddd');
document.getElementById('today').style.color = 'green';
})
}
function showData(data){
console.log(data)
}