0

My Code is as such:

for (var i=0; i < numaccounts; i++) { 
    $.post('assets/ajax/multi-save.php', appointments[i], function(data) {
      alert(appointments[i]);
      alert(appointments[0]);
    });
}

the problem seems to be with my array appointments. The second with the fixed offset of 0 displays fine. The one using 'i' displays as 'undefined'. If I alert(i) it is always '2'.

3
  • can you post the array 'appointments' also? also what is numaccounts? should it be numaccounts.length? Commented Apr 23, 2015 at 20:09
  • The array isn't the issue because if I set the offset manually it displays in the same space. The issue is how do I get the i counter inside the .post function. It only seems to show up as the terminating value of 2. Commented Apr 23, 2015 at 20:12
  • and what is numaccounts? Commented Apr 23, 2015 at 20:15

1 Answer 1

0

Ah, all it took was a little more searching:

jQuery ajax inside a loop problem

Explains the problem and gives the solution.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.