私は条件をチェックするようにコードを設定しており、その条件に基づいてajax呼び出しを実行してJSONオブジェクトを取得するか、または別の処理形式に進むことができます。処理後、if/elseステートメントで処理されたデータに基づいていくつかの処理を行います。jQuery - ".get"コールが完了するまで処理を遅らせる場合は
しかし、私は問題に遭遇しています。コードはif/elseを実行し、.getが処理を終了する前に続き、最後のコードが正常に動作しません。 .getが完了するまで、残りのコードの処理を遅らせる方法はありますか?
次のように私のコードの構造は次のとおりです。
if(filename != undefined){
$.get(filename, function(json){
$.each(json, function(data){
// Do stuff with the json
});
}, "json");
} else {
// Do some other processing
}
// Do some additional processing based on the results from the if/else statement
// This bit is getting processed before the .get has finished doing it's thing
// Therefore there isn't anything for it to act upon
@Kevin - これは必ずしも最良の選択ではありません。特にajaxリクエストが長すぎるとハングアップする場合は特にそうです。 – Neal
Thx Neal、それは本当です。私は答えに追加します – beefyhalo