Calling a PHP function from a JS function, using parameters
<p>I would like to use a JS function to call a PHP function using a parameter.<br><br>
So the JS function ipOpts() will call the PHP function getColumns() using the myField as a parameter.<br><br>
I have tried to do something but it's not working.<br><br>
<hr><br></p>

<p>JS file:</p>

<pre><code>var ipOptsArray= new Array({"label" : "a", "value" : "a"});

function ipOpts(myField){
ipOptsArray.splice(0,1);
$.ajax({
  url: './get_fields.php?myField='+myField,
  async: false,
  dataType: 'json',
  success: function (json) {
      for(var a=0;a&lt;json.length;a++){
        obj= { "label" : json[a][0], "value" : json[a][1]};
        ipOptsArray.push(obj);
      }
    }
});
return ipOptsArray;
}
</code></pre>

<p><br><hr><br>
PHP file:</p>

<pre><code>&lt;?php

 function getColumns($myField){
$connection = mysql_connect('localhost', 'mbrconsu_un394x', 'y1cz9,rd+hf6') or die(mysql_error());
mysql_select_db('mbrconsu_mmx', $connection) or die(mysql_error());

$sql="SELECT * FROM treinamentos ORDER BY" '$myField' "ASC";
$result = mysql_query($sql);
$stack=array();
    while($row = mysql_fetch_array($result))
          {
            array_push($stack,array($row[$_GET['myField']],$row[$_GET['myField']));
          }

echo json_encode($stack);
}
?&gt;
</code></pre>
