salve a tutti, ho un problema che mi sta tormentando da un po' di tempo...ho guardato su tantissimi forum ma non ne riesco a venirci a capo....vi faccio vedere il codice:
mentre il modulo php è il seguente:
ovviamente tralascio tutta la parte del database che per ora non mi interessa... il mio problema è che continua a darmi 'no variable received', se invece provo a fare una cosa di questo tipo
semplicemente mi dice "undefined index idx" ecc.
ho fatto f12 su google chrome per la pagina html e non mostra errori...ho richiamato bene la funzione ajax per passare quella variabile? spero che possiate aiutarmi, grazie mille.
Codice:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Gauge Test</title>
<script src="gauge.min.js"></script>
<style>body{padding:0;margin:0;background:#0}</style>
<script type="text/javascript" src="jquery-1.11.3.min.js"></script>
<script type="text/javascript"></script>
</head>
<body>
<p><input type="button" onclick="showGauge()" value="Show Gauge"></p>
<canvas id="gauge"></canvas>
<div id="console"></div>
<script type="text/javascript">
function showGauge() {
var kpiValue = 1;
var cont = 1;
var data = "";
var gauge = new Gauge({
renderTo : 'gauge',
width : 400,
height : 400,
glow : true,
units : 'Km/h',
title : false,
minValue : 0,
maxValue : 220,
majorTicks : ['0','20','40','60','80','100','120','140','160','180','200','220'],
minorTicks : 2,
strokeTicks : false,
highlights : [
{ from : 0, to : 50, color : 'rgba(0, 255, 0, .15)' },
{ from : 50, to : 100, color : 'rgba(255, 255, 0, .15)' },
{ from : 100, to : 150, color : 'rgba(255, 30, 0, .25)' },
{ from : 150, to : 200, color : 'rgba(255, 0, 225, .25)' },
{ from : 200, to : 220, color : 'rgba(0, 0, 255, .25)' }
],
colors : {
plate : '#222',
majorTicks : '#f5f5f5',
minorTicks : '#ddd',
title : '#fff',
units : '#ccc',
numbers : '#eee',
needle : { start : 'rgba(240, 128, 128, 1)', end : 'rgba(255, 160, 122, .9)' }
}
});
gauge.onready = function() {
var idx = 0;
setInterval( function() {
$.ajax({
type:'POST',
url: 'prova2.php',
data: {'idx' : idx},
dataType: 'json',
success: function(data){
var n= data.length;
try{
if(idx<n){
kpiValue = data[idx];
idx = idx + 1;
}
else{
idx= 0;
}
}
catch(ex){
kpiValue = 0;
idx = 0;
}
}
});
if (kpiValue > 220){
kpiValue = 0;
}
gauge.setValue(kpiValue);
}, 1000);
}
gauge.draw();
};
</script>
</body>
</html>
Codice:
if (isset($_POST['idx'])) {
$x = $_POST['idx'];
echo $x;
echo "ok";
}else{
echo 'no variable received';
}
Codice:
$src1= $_POST['idx'];
echo $src1;
ho fatto f12 su google chrome per la pagina html e non mostra errori...ho richiamato bene la funzione ajax per passare quella variabile? spero che possiate aiutarmi, grazie mille.