I have 2 php file. One Php file uses ajax to post something to another php file.
Let's say Php 1 is called index.php while the other php is getsomething.php
Here's my index.php code with ajax(only part of the code is given here)
$(function() {
$("#datestart").on("change", function() {
var d = new Date();
var n = d.getFullYear();
var dte = new Date(n, $(this).val(), 0).getDate();
var datestart = n + "-" + $(this).val() + "-01 00:00:00";
var dateend = n + "-" + $(this).val() + "-" + dte + " 23:59:59";
var brandid = $('#txtbxbrandid').val();
//-----GENDER----//
$.ajax({ url: 'ajax/datagenderfilter.php',
dataType:'json',
type: 'post',
data: {'bidg' : brandid, 'startg' : datestart, 'stopg' : dateend},
success: function(output) {
$('#chartContainergender').remove();
$('#chartgender').append('<div id="chartContainergender" style="height: 300px; width: 100%;"></div>');
var chartgender = new CanvasJS.Chart("chartContainergender",
{
title:{
text: "Pie chart filtered by Gender"
},
legend: {
maxWidth: 350,
itemWidth: 120
},
data: [
{
type: "pie",
showInLegend: true,
legendText: "{indexLabel}",
dataPoints: output
}
]
});
chartgender.render();
},
error: function(request, status, error){
alert("Error: Could not delete");
}
});
});
});
Now here's the getsomething.php
if (isset($_POST['bidg'])) {
$brandid = $_POST['bidg'];
$datebeg = $_POST['startg'];
$dateend = $_POST['stopg'];
echo json_encode($brandid, JSON_NUMERIC_CHECK);
}
else{
echo json_encode("FAILED", JSON_NUMERIC_CHECK);
}
But everytime I tried posting it the getsomething.php skips the if and go straight to else.
Can someone check where am I going wrong.