Wednesday, June 3, 2020

Read data from database using fetch javascript



and we will fetch data from api to HTML .

The following code is :

<script>
  fetch('https://www.baznaspayakumbuh.com/api/api_tabloit_pulsa.php')
  .then(response => response.json())
  .then(data => {

                      let output = '<h2>Lists of Users</h2>';
                        output += '<ul>';
                          for(let i=0 ; i < data.result.length; i++){
                            output += `<li> ${data.result[i].title}</li>`;
                          }
                        output += '</ul>';
              document.getElementById("response").innerHTML = output;

  });
</script>
<div id="response"></div>


Happy Code ...



No comments:

Post a Comment

Set Cookie dan Remove Cookie dengan php vanilla.js

< html lang = "en" > < head >     < meta charset = "UTF-8" >     < meta name = "viewport...