title: How to call an AJAX function on page load
body: <p>I need to call GetAllProperties() function during page loading instead of calling the GetAllProperties() function after page is fully loaded.</p>
  
  <p>I tried window.onload = GetAllProperties; but it didn't work</p>
  
  <p>My code looks like this:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
   window.onload = GetAllProperties;
  
  
      function GetAllProperties() {    
          $.ajax({
              cache: false,
              url: '/Home/GetAllProperties',
              type: 'GET',
              contentType: "application/json; charset=utf-8",
              success: function (response) {
                  if (response.list.length &gt; 0) {
                      console.log(response.list)
                      var $data = $('&lt;table id="mytable"  class="table  table-striped"&gt; &lt;/table&gt;');
                      var header = "&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Property Name&lt;/th&gt;&lt;th&gt;Edit&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;";
                      $data.append(header);
                      $.each(response.list, function (i, row) {
                          var $row = $('&lt;tr/&gt;');
                          $row.append($('&lt;td/&gt;').html(row.PropertyName));
                          $hidden = $(' &lt;input type="hidden" name="hid" value= "' + row.PropertyId + '"&gt;');
                          $row.append($hidden);
                          $editButton = $("&lt;button class='editbtn' id='mybtn'&gt;Edit&lt;/button&gt;");    
                          $row.append($editButton);
                          $deleteButton = $("&lt;button class='deletebtn' id='delbtn'&gt;Delete&lt;/button&gt;");    
                          $row.append($deleteButton);
                          $data.append($row);
                      });        
                      $("#MyDiv").empty();
                      $("#MyDiv").append($data);
                  }
                  else {
  
                  }
              },
              error: function (r) {
                  alert('Error! Please try again.' + r.responseText);
                  console.log(r);    
              }
          });    
      }    
  &lt;/script&gt;
  </code></pre>