In console it is showing the obj but in very next line when I'm trying to access it shows an error: cannot read property 'date' of undefined. I'm not getting what is the mistake.
I tried following: console.log(obj[9].date)
Please go through success : function(obj)
<script type="text/javascript">
$("#date-picker").flatpickr({
defaultDate : new Date()
});
console.log($("#date-picker").val());
$("#date-picker").on('change',function(){
console.log($("#date-picker").val());
var select_date = $("#date-picker").val();
console.log("select_date : ",select_date);
$.ajax({
type: "POST",
url: "http://127.0.0.1:8000/attendance/",
dataType: 'json',
async: true,
data: {
"selected" : '1',
"select_date" : select_date,
csrfmiddlewaretoken : '{{ csrf_token }}'
},
success: function(obj){
console.log("post alerts");
console.log("success");
console.log(obj);
console.log(obj[9].date);
failure: function(data){
console.log("failure");
console.log(data);
},
});
})
</script>
console.log(JSON.stringify(obj))
shows:
{
"obj": [{
"student_id": 1,
"date": "2019-06-20",
"check_in": "2019-06-19T11:27:52.692Z",
"check_out": "2019-06-19T11:27:52.693Z",
"tutor_time": "2019-06-19T11:27:52.693Z",
"intention": "",
"absent_present": "",
"reasonOfAbsence": ""
}, {
"student_id": 2,
"date": "2019-06-20",
"check_in": "2019-06-19T11:27:52.762Z",
"check_out": "2019-06-19T11:27:52.762Z",
"tutor_time": "2019-06-19T11:27:52.762Z",
"intention": "",
"absent_present": "",
"reasonOfAbsence": ""
}],
...
}