私は2つのコールバックを持っています。そのうちの1つはブール値を返し、もう1つはajax呼び出しを行う必要があります。 2番目の結果から結果を得ることはできません。コールバック関数から返されるajaxの結果
私はreturn the response from an asynchronous callの方法の説明を読みましたが、結果は得られません。
私のコードがあります:
if($.fn.wizard) {
$('#wzd-enrollment').wizard({
//some code
onStepLeave: function (wizard, step){
//in this function i have always to return a boolean value to move to the next step or not
var result;
result = doAjax(wizard, step);
console.log(result); //always log undefined
return result;
}
});
function doAjax(wizard, step){
if(step.id == 'step-1'){
//some code
$.ajax({
type: "GET",
dataType: 'json',
url: s_url,
}).done(function(data) {
//some code
return true;
}).fail(function(jqXHR, textStatus, errorThrown){
//some code
return false;
});
}else{
return true;
}
}
}
あなたが天気をかを伝えることができないので、あなたは非同期機能 –
から何かを返すことはできませんそれが呼び出されるとき。またはどのくらい頻繁に。 Promiseを使用すると、jQueryが提供します。 – Thomas
あなたのリプレイに感謝しますが、私は何をすべきですか? –