我想我在最新的 jQuery 3.3.1 中发现了错误。我的问题看起来像这样 - 当我尝试使用 getJSON 函数将索引作为数字 0 或字符串 0 发送时,我没有得到任何响应。尝试其他数字或字符串并完美运行。
我的js:
var index = 0;
$.getJSON('/ajax.php' , { index: index }, function(r) {
console.log( r );
}, 'jsonp');
我的示例 php:
header('Content-Type: application/json');
$index = intval( $_GET['index'] );
file_put_contents('log.txt' , $index);
die(json_encode([
'received' => $index
]);
在 log.txt 我发现 0 和我发送到的任何其他数字,但如果 0 是我在 console.log json 响应中没有看到的索引 {received: 0}