Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

217
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda