jQuery ajax inside a loop problem

Posted by steamboy on Stack Overflow See other posts from Stack Overflow or by steamboy
Published on 2010-04-22T01:27:35Z Indexed on 2010/04/22 1:33 UTC
Read the original article Hit count: 280

Filed under:
|
|

Hello,

This js loop script always get the last value of ui_item inside a jquery ajax funciton. How can a catch the correct value of each iteration?

for (var i = 0; i <= split_files_cb_value_holder.length - 1; i++){
    var split_values = split_files_cb_value_holder[i].split(':');

    ui_item = split_files_cb_value_holder[i];

    $.ajax({
        type: "POST",
        url: "ds/index.php/playlist/check_folder",
        data: "component_type="+$('#component_type').val()+"&value="+split_values[1],
        success: function(msg)
        {
            console.log(ui_item); //ALWAYS GETS THE LAST VALUE
        },
        error: function()
        {
            alert("An error occured while updating. Try again in a while");
        }
    });

}

Thanks!

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about loop