title: user ajax to get data without "onClick function" in javaScript
body: <p>I've been searching for the example of getting data by using ajax without onclick function but most of the example that i found was within onclick funtion.<br/>
  Here is the html that i successfully get the data by using Onclick funtion</p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
     &lt;meta charset="utf-8" /&gt;
     &lt;title&gt;New document&lt;/title&gt;
  
     &lt;script type = 'text/javascript' src='js/jquery-2.2.0.js'&gt;&lt;/script&gt;
  
  &lt;script type ='text/javascript' src='js/testScript.js'&gt;&lt;/script&gt;
  
  &lt;?php
  include_once("database_conn_getOffers.php");
  ?&gt;
  &lt;/head&gt;
  &lt;body&gt;
     content goes here
     &lt;aside id="offer" onclick ="loadDoc('getData.php',myFunction)"&gt;
          &amp;nbsp; click here
          &lt;/aside&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>
  here is the script</p>
  
  <pre><code>function loadDoc(url, cFunction) {
    var xhttp;
    xhttp=new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
      if (this.readyState == 4 &amp;&amp; this.status == 200) {
        cFunction(this);
      }
    };
    xhttp.open("GET", url, true);
    xhttp.send();
  }
  function myFunction(xhttp) {
    document.getElementById("offer").innerHTML =
    xhttp.responseText;
  }
  </code></pre>
  
  <p>Now, i wanted get the data without the onclick function. <br/>
  I want the data show once i open the html.<br/>
  Can someone provide me some link or gv me an example ??</p>