AJAX リクエストが完了するのを待ちたいと思います。xmlhttp.open
メソッドがサポートしていれば簡単ですasync = false
が、Ant Galio はこのオプションをサポートしておらず、非同期リクエストのみが許可されています。問題は、コールバックが呼び出されるのをどのように待つことができるかです。
var ajaxFinished = false;
var xmlhttp = new XMLHttpRequest();
this.debug("-- onreadystatechange is being defined");
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4) {
ajaxFinished = true;
var data = xmlhttp.responseText;
if (xmlhttp.status == 200) {
that.debug('downloadSettings: SUCCESS');
[...]
} else {
that.debug('downloadSettings:');
that.debug('-- Error: ');
that.debug('-- ResponseText: "'+data+'"')
}
}
}
while (ajaxFinished == false) {
}
this.debug("-- open connection");
xmlhttp.open("GET", requestUrl, true); /* Ant Galio does not support synchronous */
this.debug("-- send");
xmlhttp.send();
私はある種のアクティブな待機を探しています。別の解決策については知っていますが、上記の例よりも多くのコードを変更する必要のない解決策に興味があります。
ありがとう!