在下面的代码中,是否可以从else块调用错误函数?
$.getJSON('something.php', function(data) {
if (data.error === undefined) {
} else {
// How can I call the error function below?
}
}).error(function() {
// This is the error function the be called.
});
Run Code Online (Sandbox Code Playgroud)
只需单独定义并调用它:
$.getJSON('something.php', function(data) {
if (data.error === undefined) {
} else {
// How can I call the error function below?
handleError();
}
}).error(handleError);
function handleError() {
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
74 次 |
| 最近记录: |