Problem with variable 0 and jQuery $.getJSON as param

83 Views Asked by At

I think I found bug In latest jQuery 3.3.1. My problem looks like this - when I try to send index as number 0 or string 0 using getJSON function I doesn't get any response. Trying other numbers or string and works perfectly.

My js:

var index = 0;
$.getJSON('/ajax.php' , { index: index }, function(r) {
   console.log( r );
}, 'jsonp');

My example php:

header('Content-Type: application/json');
$index = intval( $_GET['index'] );
file_put_contents('log.txt' , $index);
die(json_encode([
    'received' => $index
]);

In log.txt i found 0 and any other numbers that I send to, but if 0 is as index I didn't see in my console.log json response {received: 0}

0

There are 0 best solutions below