Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="es" dir="ltr">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>JQUERY</title>
  6. </head>
  7. <style>
  8. .parrafo{
  9. background-color:#226677;
  10. }
  11. </style>
  12. <body>
  13. <h5>P Mostrar</h5>
  14. <p name="mostrar" class="parrafo">
  15. asdasdasdasdas
  16. </p>
  17. <h5>P sin attr name</h5>
  18. <p></p>
  19. <p id="datosrest"></p>
  20. <button name="actionBuscar">RUN</button>
  21. <button name="consumirRest">GET API utilizando AJAX Simplificado</button>
  22. <script src="js/jquery.js"></script>
  23. <script>
  24. /*
  25. $(selector).evento();
  26. */
  27. $(document).ready(function(){
  28. $("button[name='actionBuscar']").click(function(){
  29. texto = "Lorem Ipsum dolo sit at men";
  30. $("p[name='mostrar']").css("background-color","#445566").html(texto);
  31. });
  32. $("button[name='consumirRest']").click(function(){
  33. url_endpoint = "https://jsonplaceholder.typicode.com/posts";
  34. $.get(url_endpoint,function(datos){
  35. //console.log(datos);
  36. html = "";
  37. $.each(datos, function(k,v){
  38. html += "<strong>ID</strong>: "+v.id+"<br />";
  39. html += "<strong>Título</strong>: "+v.title+"<br />";
  40. });
  41. $("#datosrest").html(html);
  42. });
  43. });
  44. });
  45. </script>
  46. </body>
  47. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement