Advertisement
NubeColectiva

test

Jul 30th, 2023 (edited)
1,115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.74 KB | Source Code | 0 0
  1. const xmlhttp = new XMLHttpRequest();
  2. xmlhttp.onload = function() {
  3.   const myObj = JSON.parse(this.responseText);
  4.   console.log(myObj)
  5.    
  6.     myObj.forEach(function(o) {
  7.        document.getElementById("datos").innerHTML += '<li>' + o.nombre + '</li>';
  8.     })
  9.  
  10. };
  11. xmlhttp.open("GET", "api/v1/productos/listar");
  12. xmlhttp.send();
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19. const xhttp = new XMLHttpRequest();
  20. xhttp.onload = function() {
  21.     document.getElementById("datos").innerHTML = this.responseText;
  22. }
  23.  
  24. const miobj = { name: "Televisor", precio: 300, stock: 19, img: "tv.jpg" };
  25. const mijson = JSON.stringify(miobj);
  26.  
  27. xhttp.open("POST", "api/v1/productos/insertar");
  28. xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  29. xhttp.send(mijson);
Tags: php
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement