const xmlhttp = new XMLHttpRequest();
xmlhttp.onload = function() {
const myObj = JSON.parse(this.responseText);
console.log(myObj)
myObj.forEach(function(o) {
document.getElementById("datos").innerHTML += '
' + o.nombre + '';
})
};
xmlhttp.open("GET", "api/v1/productos/listar");
xmlhttp.send();
const xhttp = new XMLHttpRequest();
xhttp.onload = function() {
document.getElementById("datos").innerHTML = this.responseText;
}
const miobj = { name: "Televisor", precio: 300, stock: 19, img: "tv.jpg" };
const mijson = JSON.stringify(miobj);
xhttp.open("POST", "api/v1/productos/insertar");
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send(mijson);