Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const xmlhttp = new XMLHttpRequest();
- xmlhttp.onload = function() {
- const myObj = JSON.parse(this.responseText);
- console.log(myObj)
- myObj.forEach(function(o) {
- document.getElementById("datos").innerHTML += '<li>' + o.nombre + '</li>';
- })
- };
- 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);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement