Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

209
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!