これが私のコードのサンプルです。不要な部分を削除しました。グローバル変数を設定しましたrecipient
。アラートである必要があります1
が、何もアラートされていません。関数の外に設定された変数を変更する正しい方法は何ですか? どうすればこれを解決できますか?
var recipient = 0;
$("#submit-button").click(function () {
$.getJSON("/fetch.php?o=4&user=" + k, function (B) {
$.each(B, function (index, result) {
recipient = 1;
})
})
if (recipient == 1) {
alert("yes");
}
})