title: ajax not loading content in DOM
body: <p>instead of populating the "tempDiv" in html, the print.php is loaded showing the content. The same code is working for other files and javascript functions. :/</p>
  
  <p>HTML:</p>
  
  <pre><code> &lt;li&gt;&lt;a class="button black" href="#searchbox" onclick="viewall()" &gt;View All&lt;/a&gt;&lt;/li&gt;
   &lt;li&gt;&lt;button class="button black" type="submit" form="selectcol" onclick="printDiv()"&gt;&lt;/button&gt;&lt;/li&gt;
        &lt;div id="searchresults"  style="padding-top:30px; padding-bottom:10px; max-height:280px; "&gt;
       The results will show up here..!!
       &lt;/div&gt;
  
    &lt;div id="tempDiv"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>The viewall() function :</p>
  
  <pre><code>function viewall(){
  
  var xmlhttp;
  
  if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
    }
  else
    {// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    /*
  xmlhttp.onreadystatechange=function()
    {
    if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200)
      {
      document.getElementById("searchresults").innerHTML=xmlhttp.responseText;
      }
    }*/
  
  
  
    xmlhttp.open("POST", "viewall.php", true);            // set the request
    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");            // adds  a header to tell the PHP script to recognize the data as is sent via POST
    xmlhttp.send();       // calls the send() method with datas as parameter
  
    // Check request status
   // If the response is received completely, will be transferred to the HTML tag with tagID
    xmlhttp.onreadystatechange = function() {
      if (xmlhttp.readyState == 4) {
        document.getElementById("searchresults").innerHTML = xmlhttp.responseText;
      }
    }
  
  }
  </code></pre>
  
  <p>The printDiv() function called to print the selected columns:</p>
  
  <pre><code>function printDiv()
  {
  
  var xmlhttp;
  
  if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
    }
  else
    {// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    /*
  xmlhttp.onreadystatechange=function()
    {
    if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200)
      {
      document.getElementById("searchresults").innerHTML=xmlhttp.responseText;
      }
    }*/
  
  
  
    xmlhttp.open("POST", "print.php", true);          // set the request
    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");            // adds  a header to tell the PHP script to recognize the data as is sent via POST
    xmlhttp.send();       // calls the send() method with datas as parameter
  
    // Check request status
   // If the response is received completely, will be transferred to the HTML tag with tagID
    xmlhttp.onreadystatechange = function() {
      if (xmlhttp.readyState == 4) {
        document.getElementById("tempDiv").innerHTML = xmlhttp.responseText;
      }
    }
  
  
  
  }
  </code></pre>
  
  <p>PHP :</p>
  
  <pre><code>&lt;?php
  
  $col = $_POST['print'];
  
  $flds = "";
  foreach($col as $value){
  
  if(isset($col)){
  if($flds !="") 
  $flds .= ",";
  $flds .= $value;
  }
  
  }
  
  $sql = "SELECT ". $flds." from student";
  
  
  
  $con = mysqli_connect("localhost", "root", "","university") or die("could not connect". mysqli_error($con));
  $rs = mysqli_query($con, $sql);
  
  
  echo "&lt;table border='1'";
  
  while($r = mysql_fetch_array($rs)){
  
                              echo "&lt;tr&gt;";
                              echo "&lt;td class='searchtabledata'&gt;".$r[0]."&lt;/td&gt;";
                              echo "&lt;td class='searchtabledata'&gt;".$r[1]."&lt;/td&gt;";
                              echo "&lt;/tr&gt;";
  
                  }                           
  
  
  
  ?&gt;
  </code></pre>
  
  <p>the result i get on clicking the submit button</p>
  
  <p><img src="https://i.stack.imgur.com/YoSz8.png" alt="enter image description here"></p>