我正在进行 ajax 调用以更新引导进度条,并且在 AJAX 调用成功时我有这个:
$(function () {
var percent = data['minutes'] / 30 * 100;
$('#progressbarr').html("<div class='bar' id='progressbar' style='width: "+ percent +"%;'></div>");
}
现在,我知道 data['minutes'] 返回一个数字,因为我在其他地方使用它,来自同一个 ajax 调用,但是当我执行包含该数据数组的数学运算时,我得到 Not a number????
我 100% 确定 data['minutes'] 返回一个数值
编辑 1
所有的 JS
setInterval(function(){
$.ajax({
type: "POST", // Can be "GET"
url: "ajax.php",
data: {
},
dataType: "json",
success: function (data) //on recieve of reply
{
$(function () {
var timeMinutes = data['minutes']; //get comment to post
var percent = parseInt(data['minutes']) / 30 * 100;
$('#progressbarr').html("<div class='bar' id='progressbar' style='width: "+ percent +"%;'></div>");
$('#tid').html(timeMinutes);
});
}
});
}, 3000);
所有的 PHP
$ip = $_SERVER['REMOTE_ADDR'];
$query = "SELECT * FROM `login_attempts` WHERE ip = '$ip'";
$result = mysqli_query($con, $query);
while ($row = mysqli_fetch_array($result)) {
$banned = $row['date'];
}
$start_date = new DateTime($today);
$since_start = new DateTime($banned);
$interval = $start_date->diff($since_start);
$minutes = $interval->days * 24 * 60;
$minutes += $interval->h * 60;
$minutes += $interval->i;
$TTL['minutes'] = 30-$minutes;
echo json_encode($TTL);