我有一個JavaScript函數,當我調用該函數將返回增加其在PHP中全局變量的值,JavaScript的PHP的全局變量increament
JS調用funcion是:dData()
js函數:
var dData = function() {
alert(<?php returnincreament($_SESSION['UnarJ']); ?>);
};
php函數是
function returnincreament($a){
$_SESSION['UnarJ']=$a+1;
}
我想increament警報值應1,2,3,4,5,6等
JSCODE
var datas = {
labels: ["12 AM","1 AM", "2 AM", "3 AM", "4 AM", "5 AM", "6 AM","7 AM", "8 AM", "9 AM", "10 AM", "11 AM"],
datasets: [{
fillColor: "rgba(78,156,181,.5)",
strokeColor: "rgba(2,119,158,1)",
data: [
<?php
$j=0;
for($j=0;$j<12;$j++)
{
echo round($udData[$j]);
if($j<12){
echo ",";
}
$_SESSION['udbarJ']=$j;
}
?>]
}]
};
var returndata=0;
var nextcount=0;
var dData = function() {
$.post("includes/hourlyud.php", function(data) {
//var p=data;
returndata=data;
});
return returndata;
};
var index = 11;
var currentampm="AM";
var ctxs = document.getElementById("cd").getContext("2d");
var barChartLine = new Chart(ctxs).Line(datas, {
responsive: true,
barValueSpacing: 5,
bezierCurve: false
});
var ampm = function(amorpm,cstat) {
if(amorpm===12 && cstat==="AM"){
return "PM";
}
if(amorpm===12 && cstat==="PM"){
return "AM";
}
if(amorpm>=1 && cstat==="AM"){
return "AM";
}
else return "PM";
};
setInterval(function() {
barChartLine.removeData();
barChartLine.addData([dData()], index + ampm(index,currentampm));
index++;
if(index>12){
if ((ampm(index,currentampm))==="AM"){
currentampm="PM";
}
else
currentampm="AM";
index=1;
}
}, 5500);
'$ _SESSION ['UnarJ']'實際上是否需要更新,或者你只是想增加它的客戶端? – chris85
只是想增加 –
沒有回答這個問題。 'SESSION'值是否需要增加,還是隻是增加客戶端? – chris85