H guys.
I have seen that some people already had a similar problem but by reading those posts i couldnt get my problem solve. I have an array in PHP (IQ_PHP_MODB_v4.php) whose values can be echoed and are valid (so i suppose that the php is al right.) my javascript file uses json to get the array created by PHP file. The php part of code that calls json encode is:
$out[1]=$data;
$out[2]=$leitura1;
$out[3]=$leitura2;
echo json_encode($out);
The javascript part of code that calls json is:
$.ajax({
type: 'GET',
url: 'IQ_PHP_MODB_v4.php',
async: false,
dataType: 'json',
success: function(data) {
document.write("succes");
var tensaoValor = eval(data[2]);
var correnteValor = eval(data[3]);
var potenciaValor = eval(data[1]);
var potenciaRValor = 230;
}
});
I can´t understand why JSON cant get the variable. The word succedd is never printed so i suppose that the data does not arrive to javascipt. Does anyone have an idea how to fix this? i am stucked with this since the beggining of the week.
Thanks in advance
Try removing eval()
from the code.
And, please remove async: false
. Ajax is meant to be asynchronous.