2012-03-23 15 views
2

以下のコードでは、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. 
}); 

答えて

7

ただ、別にそれを定義し、それを呼び出す:

$.getJSON('something.php', function(data) { 
    if (data.error === undefined) { 
    } else { 
     // How can I call the error function below? 
     handleError(); 
    } 
}).error(handleError); 

function handleError() { 
} 
+1

母はあなたが速く私よりも秒でした。私は同じことを書いていました。 – Miro

関連する問題