如果您正在动态创建 ajax 请求,因为它们会异步执行成功回调,您如何知道每个回调正在响应什么请求?
例子:
我有 n 个问题的数组,服务器返回答案:
var questions = Array("What's your name?", "What's your mom's name?", "What's your pet's name?");
for (var i=0; i<questions.length; i++) {
$.get ("server.php", { "Question" : questions[i] },
function(data) {
/* I want to process answer, but at this time I cannot access the value of i,
so what's question is being answered ? */
}, "json");
}