1
I have a PHP file that returns a Json.
This PHP file is called by Ajax, I have no functions in the PHP file. I receive the variables by POST in the PHP file...
Everything is working, but now I want to add functions in PHP and receive the data by parameter , at this time I am doing so:
var pesquisa = $("#pesquisa").serialize();$.ajax({
type: "POST",
url: "../Logica/info/Getinfo.php",
dataType: 'json',
data: pesquisa,
Of course, in the PHP file I have no classes or functions,
in PHP I receive the parameters by $var= $_POST["key"];
Now I want to get the file up and running... how can I do that?
function getinfo($key,$query,$datainicio,$datafim,$op){
if ($op != "" and ( $datainicio != "" and $datafim != "")) {
$query = "$querys $op and (datainicio >:datainicio AND datafim<:datafim)";
$db = new ligacao();
$conn = $db->open();
$stmt = $conn->prepare($query);
$stmt->bindParam(':datainicio', $datainicio, PDO::PARAM_STR);
$stmt->bindParam(':datafim', $datafim, PDO::PARAM_STR);
}
if ($key != "") {
$query = "$querys KEY=:KEY";
$db = new ligacao();
$conn = $db->open();
$stmt = $conn->prepare($query);
$stmt->bindParam(':KEY', $key, PDO::PARAM_STR);
}
$stmt->execute();
$result = $stmt->fetchAll();
$table = array();
$rows = array();
foreach ($result as $row) {
$rows[] = $row;
}
$table['data'] = $rows;
$json = json_encode($table);
echo ($json);
}
If I understand correctly, you want to use functions with the parameters coming via POST, just take the variables assigned as you exemplified ($var= $_POST["key"]) and pass them to the functions. Post something you’ve done in this php file so we can help.
– user28595
I’ll edit the code
– usersantos