javascript - 已定义变量的未捕获的ReferenceError

时间:2017-01-23 00:42:04

标签: javascript jquery

相关守则:

// Flag For Showing/Hiding Start Campaign Button During Alarm
var blnCampaignStatusIsgood = false;

do {
    $.ajax({
        url: "includes/getCampaigns.php,
        dataType: "json",
        cache: false,
        aysnc: false,
        success: function (res) {
            console.log("Loaded campaign info ...includes/getCampaigns.php");

            // Flag To Stop Ajax Calls
            blnCampaignStatusIsgood = true;
        },
        error: function (res) {
            console.log("Error checking for campaign info: " + res);
        }
    });
} while ( blnCampaignStatusIsGood == false );

运行时,我收到错误:

  

未捕获的ReferenceError:未定义blnCampaignStatusIsGood

在有条件的行上。

我尝试过对变量名称的各种声明(使用和不使用&#34; var&#34;),使其在脚本顶部全局,以及将ajax请求更改为同步请求。< / p>

当我在do / while循环之前明确定义它时,为什么说它未定义?

1 个答案:

答案 0 :(得分:2)

您的错误位于最后一行,blnCampaignStatusIsgood没有资本G

} while ( blnCampaignStatusIsGood == false );