'Why can't this script retrieve the data to another php file
I made my table autoload using ajax once a user enters data in the to_date date box but it seems like I can't retrieve the data to another PHP file using this script. I'm still a beginner in coding so please be easy on me. Please help. Thanks!
<script type="text/javascript">
$(document).ready(function(){
// load_data();
function load_data(fromdate, todate)
{
$.ajax({
url:"vehicle_table.php",
method:"POST",
data:{fromdate:fromdate, todate:todate},
success:function(data) {
$('.activity').html(data);
}
});
}
let to_date = document.querySelector("#to_date");
let from_date = document.querySelector("#from_date");
to_date.addEventListener("change", stateHandle);
from_date.addEventListener("change", stateHandle);
to_date.disabled = true;
var fromdate = $('#from_date').datepicker({ format: 'yyyy-mm-dd'});
var todate = $('#to_date').datepicker({ format: 'yyyy-mm-dd'});
function stateHandle() {
if(document.querySelector("#from_date").value === "") {
to_date.disabled = true;
$('.activity').html('');
} else {
if(document.querySelector("#to_date").value === ""){
to_date.disabled = false;
$('.activity').html('');
} else {
to_date.disabled = false;
$.ajax({
url:"vehicle_table.php",
method:"POST",
data:{fromdate:fromdate, todate:todate},
success:function(data) {
$('.activity').html(data);
}
});
}
to_date.disabled = false;
$('.activity').html('');
}
}
$(document).ready(function(){
$.datepicker.setDefaults({
dateFormat: 'yy-mm-dd'
});
});
});
</script>
These are my from_date and to_date.
<form action="vehicle_table.php" method="post">
<div class="col-md-4">
<label for="from_date"></label>
<input type="date" name="from_date" id="from_date" class="form-control datepicker input" placeholder="From Date" />
</div>
<div class="col-md-4">
<label for="to_date"></label>
<input type="date" name="to_date" id="to_date" class="form-control datepicker input2" placeholder="To Date" />
</div>
</div>
</form>
I didn't see any error but it didn't get pass through the
if(isset($_POST['fromdate'],$_POST['todate']))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
