オプション:別の関数のパラメータとしてオプション機能のパス
myAjax("http://ajaxurl.com", { prop: val }, function(resp) { alert(resp); });
または
function handleSuccess(resp) { alert(resp); }
myAjax("http://ajaxurl.com", { prop: val }, handleSuccess);
または
myAjax("http://ajaxurl.com", { prop: val }, null);
または
myAjax("http://ajaxurl.com", { prop: val }); // param not even provided
これはmyAjax関数定義でどのように処理できますか?このようなもの...?
function myAjax(url, jsonData, successFunc) {
$.ajax({
... all the necessary ajax stuff that normally goes here
, success: function(response) {
// custom myAjax success handling goes here. this must happen before optionally-passed-in successFunc gets executed
// what goes here? this?
if (typeof successFunc != 'undefined' && successFunc != null) {
successFunc(response);
}
}
});
}
私は上記のようなことを試みましたが、成功関数を呼び出さなかった。 successFuncが関数であるかどうかチェックする必要がありますか?
ありがとうございます!
'typeof演算successFunc ==「function'' – Kenaniah
の代わりに、またはそれに加えての?ありがとう! –