jquery ajax给callback传域

var table = $("table#output");
for( var i in items ) 
{
    (function(){
        var thisItem = items[i];
        $.getJSON("myService", { "itemID": thisItem }, function(json) 
        {
            var str = "<tr>";
            str += "<td>" + thisItem + "</td>";
            str += "<td>" + json.someMember + "</td>";
            str += "</tr>";
            table.append(str);
        });
    })();
}


原文: http://stackoverflow.com/questions/444890/jquery-scope-or-race-condition-in-ajax-getjson

你可能感兴趣的:(jquery,Ajax,json)