我刚刚习惯了$.Deferred
,碰巧我需要使用$.Deferred - then
. 我创建了一个函数:
function processA(param1, param2) {
log = $.post('http://domain.com/process',
{
id: param1,
another: param2
}
),
set = log.then(function(html){
if (someCondition) {
console.log('Successful');
// i want to do another ajax call here
// and chain another, that does an ajax again
}
})
}
如我的代码注释中所述,我该怎么做。这样对吗?未经测试,只是在输入此内容时思考。
set = log.then(function(html){
if (someCondition) {
console.log('Successful');
$.post(....),
def = set.then(function(data){
// i want to do another thing here.
})
}
})
还有一件事,是否可以在循环中使用该函数?例如
data = [{param1:"...", param2:"..."}, {..., ...}]
$.each(data, function(k,v){
processA(v.param1, v.param2);
})