0

I have code that looks like the following:

$(document).ready(function() {
    $("#sendButton").click(function () {
        for (var i = 0; i < 119; i++) {
            setTimeout(function (i) {
                proName = proDatabase[i][0];
                proChamp = proDatabase[i][1];

...

When I run it, I get an error saying that "proDatabase[i] is undefined"... meaning the value of i in the scope of that setTimeout function is undefined. I'm trying to pass the value from the loop into the setTimeout function so that the loop executes once per second (it's currently working), so that I don't make too many AJAX calls to the server too quickly.

Despite trying to pass (i) in, it still registers as undefined.

Any ideas on this one?

Thanks!

dave
  • 62,300
  • 5
  • 72
  • 93
Vranvs
  • 1,411
  • 4
  • 17
  • 38

0 Answers0