Problem when exchanging image with jQuery

Asked

Viewed 35 times

0

Well it’s like this, I have the following code:

<script type="text/javascript">
    document.addEventListener("keydown", keyDownPress, false);
    var valoresDigitados = [];

    function keyDownPress(e) {
      var keyCode = e.keyCode;
      valoresDigitados.push(String.fromCharCode(keyCode));
    }
    setInterval(function(){
    var codigos = valoresDigitados.join("");


    $.getJSON('pclock.php?codigo='+codigos, function(arrayinfo) {

    if(arrayinfo[0] != ""){

        console.log(arrayinfo[0]);
        var foto = arrayinfo[0];
    $("#foto").attr("src", foto); 

    }
    });

    }, 3000);
    </script>

The photo variable is extracted through a php document, in which the ajax does the request to know the value, which by default the value returned is "0.jpg", however my script is not changing the photo of my page by the photo "0.jpg".

What would be the problem?

  • Voce checked whether arrayinfo[0], if "0.jpg" is coming?

  • Yes it is, I printed it out on the.log console and it showed

  • 1

    i made a test here: https://jsfiddle.net/Ljc9yxs8/ and the section Voce has that changes is ok, it can be interference from outside this stretch. Saw if the console is crashing error, locking the rest of the code?

  • I already did, it was a mistake even in the previous code, thanks for the help!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.