我在函数上使用 .then()。
但在某些情况下,该函数无法成功完成,所以我猜测这就是为什么 then() 从未被调用的原因。我可以定义在这种情况下调用的另一个函数吗?
如果初始功能失败,我想做点别的事情。
最佳答案
deferred.then( doneFilter [, failFilter ] [, progressFilter ] )
第二个参数就是为了这个目的。
$.get( "test.php" ).then(
function() {
alert( "$.get succeeded" );
}, function() {
alert( "$.get failed!" );
}
);
关于javascript - 如果函数从未调用 "then",是否可以定义 "fail"替代方案?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32647559/