Advertisement
Guest User

Untitled

a guest
Nov 21st, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.74 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <!--suppress ALL -->
  3. <html>
  4. <head>
  5.     <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  6.     <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
  7.     <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
  8.     <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
  9.    
  10.     <script>
  11.        
  12.         function getJson(){
  13.             return fetch("https://jsonplaceholder.typicode.com/users").then(el=>el.json());
  14.         }
  15.  
  16.         function fun(){
  17.  
  18.             const ret = getJson();
  19.            
  20.             ret.then(el=>{
  21.  
  22.                 let str = "";
  23.                 el.forEach(element => {
  24.                     str += element.name;
  25.                     str += "</br>";
  26.                 });
  27.                
  28.                $("#div1").html(str);
  29.             });
  30.         }
  31.  
  32.        
  33.  
  34.     </script>
  35. </head>
  36. <body>
  37.  
  38.  
  39.     <div class="container">
  40.        
  41.         <div class="row">
  42.                 <div class="col-sm">
  43.                         <div id="div1"><h2>Let jQuery AJAX Change This Text</h2></div>
  44.                 </div>
  45.         </div>
  46.  
  47.         <div class="row">
  48.             <div class = "col-sm">
  49.                 <button type="button" class="success" onclick="fun()">CLICK ME</button>
  50.             </div>
  51.         </div>
  52.     </div>
  53.  
  54.  
  55. </body>
  56. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement