wataru wataru - 1 year ago 131
Javascript Question

Uncaught TypeError: Cannot read property of null

Hello im having trouble of fixing this error

Uncaught TypeError: Cannot read property '2' of null
. This is what i want to do, if i click to the day without event the
will show but if i click the day with event the
modal will show. But my problem is when im clicking the day without event im getting an error of
Uncaught TypeError: Cannot read property '2' of null

enter image description here
here's the ajax

dayClick: function(date, allDay, jsEvent, view) {
var datee = date.format();
dataType: 'json',
"filter": 1,
"start": datee

var date = data[2];

if(date == datee){


here's the php

$start = $_POST['start'];
$select = mysqli_query($con,"SELECT * FROM appointment WHERE start = '$start'");
$check_user = mysqli_num_rows($select);
$array = mysqli_fetch_row($select);
echo json_encode($array);

Answer Source

This is most likely the result of the data being passed into your success callback being null. Accessing it like it is an array will then yield the type error you are seeing. Without know too much about your app, maybe try changing your logic to:

//your previous code then handle success like:           

            if (data === null) {
            } else {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download