I am trying to send a parameter in an AJAX call. I need to send it in a way that the receiver file can understand it as a date to be part of a mysql query.
The page receives the value as URL parameter, like this:
http://.....php?dia=2016-08-15
Then on this page I make an AJAX call to send the param as POST data, like this:
var loadDataJRZ = function(){
$.ajax({
type: "POST",
data: {dia: "<?php echo $_GET['dia']?>"},
And then in the receiver file I should get the param like this:
$dia = $_POST['dia'];
If I execute the receiver file directly in the browser, the output is ok. But running the web page, the output is an empty string.
This is the receiver file code:
$dia = $_POST['dia'];
$sql = "SELECT *
FROM dbo.LoteJuarez
WHERE fecha = '$dia'
ORDER BY fecha, hora DESC";
I guess it is a matter of variable type, then I get the value dia = 903 if I send the AJAX call without ""
, like this
data: {dia: <?php echo $_GET['dia']?>},
and I get dia="2016-08-15"
sending the call with ""
data: {dia: "<?php echo $_GET['dia']?>"},
Taking into account that a direct execution from the receiver file shows the query result as it should be, what should I change to make it work?