title: $.ajax function failing to retrieve data from database while .php file works
body: <p>So i am trying to retrieve some data from a database to present them to a webpage. The thing is that even tho I am using the same code as a function I used to retrieve some other data to be loaded to the same page, but this new function doesn't work at all. Below is the code of the script and its php file. the console.logs show me a blank array, and the functions always fails so it always alerts error. Also, i tried experimenting with initiating the variables or not, same results always, so i am kinda desperate for help</p>
  
  <p>Script </p>
  
  <pre><code>&lt;script&gt;
      function databasetoaccordion(){
  
          var arr2=[];
          alert('hi');
          $.ajax({
          type: "POST",
          datatype: "json",
          url: "databasetaccordion.php",
  
          data: {exhibitid:exhibitid,exhibitname:exhibitname,exhibitsum:exhibitsum,exhibitinfo:exhibitinfo,exhibitphoto:exhibitphoto},
  
                success: function(success){
                    var arr2 = Array.from(Object.keys(success), k=&gt;success[k]);
                     console.log(arr2);
  
                      alert('cool');
                },
                error: function(error){
                    alert("error");
                    console.log(arr2);
                }
      });
  
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>databasetoaccordion.php</p>
  
  <pre><code>&lt;?php
      session_start();
      require_once('dbconfig/config.php');
      //phpinfo();
  ?&gt;
      &lt;?php 
  
          $sql = "SELECT * FROM exhibit JOIN painterarrays ON exhibit.roomid=painterarrays.id WHERE exhibit.roomid=painterarrays.id AND painterarrays.username='". $_SESSION['username']."' ";
           $result = mysqli_query($con, $sql);
           if (mysqli_num_rows($result) &gt; 0) {    
  
      while($row = mysqli_fetch_array($result)) {
          $exhibitid=$row['exhibitid'];
          $exhibitname= $row['exhibitname'];
          $exhibitsum=$row['exhibitsum'];
          $exhibitinfo=$row['exhibitinfo'];
          $exhibitphoto=$row['exhibitphoto'];
  
          $ar=array('exhibitid'=&gt;$exhibitid,'exhibitname'=&gt;$exhibitname,'exhibitsum'=&gt;$exhibitsum,'exhibitinfo'=&gt;$exhibitinfo,'exhibitphoto'=&gt;$exhibitphoto);
          $c= json_encode($ar);
          echo $c;
          echo 'hope it works';
  
      }
    } else {
      echo "0 results";
  }
  
  mysqli_close($con);
  ?&gt;
  </code></pre>