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

108
Views
use index as part of jQuery Ajax return data

I need to use the index from a for loop to check values in 10 columns QUESTION_1_ANSWER, QUESTION_2_ANSWER, QUESTION_3_ANSWER ... etc.return from jQuery Ajax.

Return surveyResults object: {question_1_Answer: 'Other', question_1_Other_Answer: 'Naples Florida', question_2_Answer: '', question_2_Other_Answer: '', question_3_Answer: '', …}

I tried to create a variable, however it does not work. Any thoughts?

        ({  type: 'POST',
            url: 'getEmployeeSurveyResults.php', 
            dataType: 'json',
            data:   {surveyID: surveyID,
                     sessionEmployeeNumber: sessionEmployeeNumber,
                    },
            cache: false,
        
            success: function (data) { 
                                        $.each(data, function (i, surveyResults) {
                                
                                            for (i = 1; i < 11 ; i++) { 

                                                var surveyResultsQuestionAnswer='surveyResults.question_'+i+'_Answer' 

                                                console.log( 'surveyResultsQuestionAnswer: ' + surveyResultsQuestionAnswer );
                                        
                                                    if(surveyResultsQuestionAnswer !==''){ 
                                                                                       
                                                                                        Do something ....
                                                                                   }                                                                                             
                                            }                               
   
                                        });
            }, 
            error: function(jqXHR, textStatus, errorThrown) { 
                                                                alert('Error: ' + textStatus + ' ' + errorThrown) 
            }
 }); //* End - $.ajax
over 4 years ago · Santiago Trujillo
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!