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

143
Views
How to access a variable from outside of Ajax code
I would like to make fileContent variable available outside of $.ajax code.

var fileContent = "";

$.ajax({
method: "POST",
url: "php/somefile.php",
data: {"nazwaProduktu": "nazwa produktu"},
}).done(function( data ) {
        var result = $.parseJSON(data);
        if (result!== null){
            var len = result.length;
                for(var i=0; i<len; i++){
                    fileContent=fileContent+result[i].nazwa+";";
                    fileContent=fileContent+(result[i].komentarz)+"\n";
                }
            }
        }
);

console.log(fileContent); //here I see fileContent empty! I need to have it updated by the above code.

Can you please advice how can I do this?

about 4 years ago · Juan Pablo Isaza
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!