Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>POST y GET</title>
  8. </head>
  9. <body>
  10. <input type="text" name="nombre">
  11. <button>Enviar</button>
  12. <div class="muestra"></div>
  13. <script src="js/jquery.js"></script>
  14. <script>
  15. $(document).ready(function(){
  16. $("button").click(function(){
  17. //ajax simplificado
  18. /*
  19. $.post('http://localhost/cursos-www/ejercicios-curso-html5/ejercicios-jquery/rest.php',
  20. {nombre:$("input[name='nombre']").val()},
  21. function(data){
  22. alert(data);
  23. });
  24. */
  25. $.get('https://jsonplaceholder.typicode.com/posts',function(data){
  26. var html = "";
  27. $.each( data, function( llave, valor ) {
  28. //console.log( "Titulo: "+valor.title +", Body: "+ valor.body );
  29. html += "<h1>"+valor.title+"</h1>";
  30. html += "<p>"+valor.body+"</p>";
  31. });
  32.  
  33. $(".muestra").html(html);
  34. });
  35. });
  36. });
  37. </script>
  38. </body>
  39. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement