Advertisement
Guest User

Untitled

a guest
Jul 15th, 2019
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  5. <title>DEMO2</title>
  6. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  7.  
  8. <script type="text/javascript">
  9.  
  10. function GetAllFormandos(){
  11. $.ajax({
  12. method: "GET",
  13. url: "http://rest.learncode.academy/api/learncode/friends",
  14. success: function(data, textStatus){
  15. console.log(data);
  16. console.log(textStatus);
  17.  
  18. $('#listaFormandos > li:eq(0)').siblings().remove();
  19.  
  20. $.each(data, function(index, item){
  21. if(item['name']){
  22.  
  23. var $newItem = $('#listaFormandos > li:eq(0)').clone();
  24.  
  25. $newItem.removeClass('hidden');
  26. $newItem.text(item['name']);
  27.  
  28. $('#listaFormandos').append($newItem);
  29. }
  30. });
  31. }
  32.  
  33. });
  34. }
  35.  
  36. $(document).ready(function () {
  37.  
  38. GetAllFormandos();
  39.  
  40. $('#btnAdd').on('click',function(){
  41. $.ajax({
  42. method: "POST",
  43. dataType: "JSON",
  44. url: "http://rest.learncode.academy/api/learncode/friends",
  45. data: { name: $('#addFormando').val()},
  46. success: function(){
  47. GetAllFormandos();
  48. $('#addFormando').val('');
  49. }
  50. });
  51. });
  52. });
  53. </script>
  54.  
  55. <style type="text/css">
  56. .hidden{display: none;}
  57. </style>
  58. </head>
  59.  
  60. <body>
  61. <h1>Lista de Formandos:</h1>
  62. <ul id="listaFormandos">
  63. <li class="hidden"></li>
  64. </ul>
  65.  
  66. <input type="text" id="addFormando" />
  67. <br/>
  68. <button id="btnAdd">Adicionar</button>
  69. </body>
  70. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement