for(var i =0; i < featuredItems.length; i++) {
var item = featuredItems.eq(i).text().trim();
alert(item); // alerts correctly
$.ajax({
url : "/documents/ajax/" + item,
dataType : "text",
success : function(data) {
/*
alerts the value set in the last iteration of for loop.
I want the same value as value of item in the ajax request URL
*/
alert (item);
},
});
}
如何在成功处理程序中正确访问 var 项的值?
上面的代码警告在for 循环的最后一次迭代中设置的值