Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

215
Visualizações
Ajax, Uncaught ReferenceError: data is not defined

I'm trying to upload a photo and pass it's data and one more data on another php file.When I select the photo and upload it a current php file give an error: Uncaught ReferenceError: PZ71AUGW5O295 is not defined. PZ71AUGW5O295 is the teamCode which gets.Sorry for the possible grammatical mistakes.

<?php

$teamCode = $_GET['tc'];

?>

var uploader = {
    url: "faces.php",
    method: "POST",
    success: function (data){
        
    }
};

function update() {
    searchParams = new FormData();
    searchParams.append('teamCode', <?php echo $teamCode;  ?>); // the error will be here
    searchParams.append('selfie', document.getElementById("faceinput").files[0]);

    uploader.cache = false;
    uploader.contentType = false;
    uploader.processData = false;
    uploader.xhr = function () {
        var jqXHR = null;
        if (window.ActiveXObject) {
            jqXHR = new window.ActiveXObject("Microsoft.XMLHTTP");
        } else {
            jqXHR = new window.XMLHttpRequest();
        }
        //Upload progress
        jqXHR.upload.addEventListener("progress", function (evt) {
            if (evt.lengthComputable) {
                var percentComplete = Math.round((evt.loaded * 100) / evt.total);
                //Do something with upload progress
                $(".progress-bar").css("width", percentComplete + "%");
            }
        }, false);
        return jqXHR;
    }
    uploader.data = searchParams;
    $.ajax(uploader);
}

After I upload the photo I get the error:

Uncaught ReferenceError: PZ71AUGW5O295 is not defined
at update (upload_photo.php?tc=PZ71AUGW5O295:86)
at HTMLInputElement.<anonymous> (upload_photo.php?tc=PZ71AUGW5O295:71)
at HTMLInputElement.dispatch (jquery.min.js:3)
at HTMLInputElement.r.handle (jquery.min.js:3)
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You are just echoing your php variable in js, then that parsed data would be transferred to js code, so now look what your js code would look like.

searchParams.append('teamCode', PZ71AUGW5O295);

In this case js would try to look whether PZ71AUGW5O295 variable exists, of course its not.

Other then that it look like your are doing a lot of things in a not good way. f.e. passing image with GET not POST, getting submitted with php image to create another request. Whats the idea? Just build your request in image upload page with js and then pass it, whats the idea of having php code to then again send another request.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda