Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.

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

share|improve this question
    
try removing evals from your code. –  Kita Oct 4 '13 at 13:17
2  
Stop using document.write and eval, it probably won't solve the problem, but it's a great start. –  adeneo Oct 4 '13 at 13:17
    
What does the console say about the request? Do you get an HTTP error? –  Explosion Pills Oct 4 '13 at 13:18
    
You really need to bring up your browser debug tool (F12) and have a look at the network request being issued - it should include the response data as well whereby you will probably see that it's not valid JSON data or indeed that some other error occurred during the request. –  Stephen Byrne Oct 4 '13 at 14:49

1 Answer 1

Try removing eval() from the code.

And, please remove async: false. Ajax is meant to be asynchronous.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.