title: onClick function to get array from different php file
body: <p>I would like to get array from new.php file into index.php via ajax function</p>
  
  <pre><code>function retrieve() {
  $.ajax({
      url: 'new.php',       
      data: "",
      dataType: 'json',    
      success: function (data) {
          alert(data);
      }
  });
  }
  </code></pre>
  
  <p>In new.php I get array from sql query. </p>
  
  <pre><code>while ($row = $query2-&gt;fetch_assoc()) {
      $port_list[] = $row['port_name'];
  
  }
  mysqli_close($con);
  echo json_encode($port_list);
  </code></pre>
  
  <p>and in <code>index.php</code> I have <code>$list = $_POST['$port_list'];</code> </p>
  
  <p>How can I get values from different PHP file into another without using <code>session, cookies, form..?</code> </p>