title: How to show a html table with data from database using ajax?
body: <p>Im a newbie in web development and I really need some help.I want to show a html table using ajax. This codes are from two different files. Am i doing this right??</p>
  
  <p>here is my index.html</p>
  
  <pre><code>&lt;html&gt;
      &lt;body&gt;
  
  &lt;script&gt;
  function loadXMLDoc()
  {
      var xmlhttp;
      xmlhttp=new XMLHttpRequest();
  
      xmlhttp.onreadystatechange=function()
        {
        if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200)
          {
          document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
          }
      }
      xmlhttp.open("GET","table.php",true);
      xmlhttp.send();
  }
  &lt;/script&gt;
  
          &lt;form action = "insert.php" method="post"&gt;
  
          Firstname: &lt;input type="text" name="firstname"&gt;&lt;/br&gt;
          Lastname: &lt;input type="text" name="lastname"&gt;&lt;/br&gt;
          Middlename: &lt;input type="text" name="middlename"&gt;&lt;/br&gt;
  
          &lt;input type="submit" onclick="loadXMLDoc()"&gt;
  
  
          &lt;/form&gt;
          &lt;div id="myDiv"&gt;&lt;/div&gt;
  
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>here is my table.php. When i click the submit button nothing happens. Is there someone who can tell me if Im doing this right??</p>
  
  <pre><code>&lt;html&gt;
      &lt;body&gt;
          &lt;table border = 1&gt;
              &lt;tr&gt;
                  &lt;th&gt;FIRSTNAME&lt;/th&gt;
                  &lt;th&gt;LASTNAME&lt;/th&gt;
                  &lt;th&gt;MIDDLENAME&lt;/th&gt;
                  &lt;th&gt;DELETE&lt;/th&gt;
              &lt;/tr&gt;
  
  
  
      /*  &lt;?php
                  $con = mysqli_connect("localhost","root","","study");
  
                  if (mysqli_connect_errno($con))
                      {
                          echo "Failed to connect to mysql" . mysqli_connect_error();
                      }
  
                      $result = mysqli_query($con,"SELECT * FROM sample_employers");
  
                      while($row=mysqli_fetch_array($result))
                      {
                          echo "&lt;tr&gt;";
                          echo "&lt;td&gt;" . $row['firstname'] . "&lt;/td&gt;";
                          echo "&lt;td&gt;" . $row['lastname'] . "&lt;/td&gt;";
                          echo "&lt;td&gt;" . $row['middlename'] . "&lt;/td&gt;";
                          echo "&lt;td&gt; &lt;input type='button' value='Delete' &lt;/td&gt;"; 
                          echo "&lt;/tr&gt;";
                      }
  
                      mysqli_close($con);
              ?&gt;
  
          &lt;/table&gt;
          &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>