I want to show day into textbox based on my input date
here is my ajax to change the textbox :
$("#date").change(function(){
$.ajax({
url : "<?php echo base_url();?>daftar/get_day",
method : "POST",
data : {date: $("#date").val()},
async : false,
success: function(data){
$("#day").val(day);
}
});
});
this is my controller :
function get_day()
{
$date=$this->input->post('date');
$this->load-model('daftarmodel');
$day = $this->daftarmodel->geDay($date);
echo $day;
}
this is my model :
function getDay($date){
$timestamp = strtotime($date);
$day = date('D', $timestamp);
var_dump($day);
return $day;
}
is there anything wrong with my code which not showing the day
CodePudding user response:
Not sure if this is the part of your problem, but looks like you may be using the wrong variable in your ajax success.
success: function(data){
$("#day").val(day);
}
you could try replacing "day" with the "data" variable that is in your: "success: function(data)"
success: function(data){
$("#day").val(data);
}
CodePudding user response:
First of all you need to remove var_dump($day); from your model. Secondly need to little bit improvement in your understanding . Ajax call return response in case of successfully execution ajax return result in success function. In you case it will return day in data.
success: function(data){
$("#day").val(data);
}