title: PHP script not getting called from ajax function
body: <p>this is a noob question.</p>
  
  <p>my javascript function(part of knockout.js model that I have defined):</p>
  
  <pre><code>self.loadData = function(){
          alert("loadData got called");
          $.ajax({
              url: 'database_connection.php',
              dataType: 'json',
              success: function(data){    //json string of records returned from server
                  alert('success from server call');              
  
              },
              error: function(){
                  alert('error from server call');            
              }
  
          });
      };
  </code></pre>
  
  <p>Contents of database_connection.php:</p>
  
  <pre><code>&lt;?php
      echo "this is called";
      $db = new MySqli('localhost', 'username', 'password', 'database');
      $activities = $db-&gt;query("SELECT * FROM MainActivity");
      $activities_r = array();
  
      while($row = $activities-&gt;fetch_array()){
          $val = $row['mActivityID'];
          $act = $row['Name'];
  
          $activities_r[] = array('val'=&gt;$val, 'act' =&gt; $act);
          }
  
          echo json_encode($activities_r);
  
  ?&gt;
  </code></pre>
  
  <p>The php is correct, coz if I directly access this file through browser, it correctly displays the result from database table.</p>
  
  <p>However, when executed through the <code>loadData</code> function, I get two alerts:
  1. <code>"loadData is called"</code>
  2. <code>"error from server call"</code></p>
  
  <p>the first line of database_connection.php is not being executed since I cant see the result of <code>echo</code>, so that means the script is not getting called.</p>
  
  <p>Am I using the <code>ajax</code> function wrongly?</p>