繁体   English   中英

全局变量未分配值

[英]Global variable doesn't get assigned the value

我不知道这个。

我有一个名为id的全局变量。

当我调用id以下的函数时,返回的msg值不会减少,我会使用底部的alert('inside bottom4 (id) =' + id) 如果我注释掉警报,则id是调用函数之前全局变量的值。

哦,顺便说一句, alert('after assignment=' + id); 具有正确的返回值。


var id = 0;

savetodb(obj);

alert(id)

function savetodb(lcalEvent) {
    var ThingID = parseInt(lcalEvent.userId);

    $.ajax({
        type: "GET",
        url: "res_update.asp",
        data: "id=" + lcalEvent.id,
        success: function (msg) {
            if (msg.indexOf('following') > 0) {
                Notices.show('error', msg, { duration: 1000 });
                $("#calendar").weekCalendar("refresh");
            } else {
                if (msg != '0') {
                    id = msg++;
alert('after assignment=' + id);
                }
                Notices.show('notice', 'Your reservation has been saved');
            }
        },
        error: function (msg) {
            alert("Data Error: " + msg);
        }
    });

alert('inside bottom4 (id) =' + id)
}

AJAX是异步的

您的success回调将在其余代码之后运行一段时间。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM