例如:
$.get('/path/to/api').then(
function(data) {
alert( "$.get succeeded" );
}, function(error) {
alert( "$.get failed!" );
}
);是否可以在这两个回调中应用回叫操作符?
发布于 2013-08-08 22:07:19
您只能在回传中使用一个函数,但是您可以做的是使用一个回传,并正常地提供另一个函数(注意使用_作为占位符来表示回调函数在参数中的位置)--例如。
data <- $.get '/path/to/api' .then _, -> alert "$.get failed!"
alert "$.get succeeded"汇编成:
$.get('/path/to/api').then(function(data){
return alert("$.get succeeded");
}, function(){
return alert("$.get failed!");
});https://stackoverflow.com/questions/18123457
复制相似问题