我有类似以下的东西:
$(".remove-item").click(function(e) {
e.preventDefault();
var url = $(this).attr('href');
var id = $(this).data("id");
$.when(removeItem(url))
.then(removeItemResponse(id));
});
var removeItemResponse = function(data, id) {
console.log(data);
console.log(id);
};
var removeItem = function(url) {
return $.post(url);
};
上面的代码不能正常运行,我在ajax请求处理后没有在日志中得到任何信息。我知道这与我在removeItemResponse中处理参数的方式有关。我需要使用ajax post返回的数据,同时还要传递click函数中检索到的id。
removeItem
定义在哪里? - marteljnremoveItem
并不相关。知道它如何定义并不能帮助将id
传递到.then
回调函数。 - Kevin B