2

I'm little stuck here, can anybody help?

I have a list of items and for each item I need to call ajax. After returning data I will process them, but with context of particular item. Please look in source code below. My problem is, that i always get i=5 for all my items. Any suggestions?

for (var i = 0; i < 5; i++) {
    $.ajax(myAjaxUrl)
        .done(function(myAjaxResponse) {
            doSomething(myAjaxResponse, i);
        })
        .fail(function() {
            console.log("ajax response fail");
            doSomething("", i);
        });
}

function doSomething(text, i) {
    console.log(text + " " + i);
}

Thanks a lot

3

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.