Global variable doesn't get assigned the value
<p>I can't figure this out. </p>

<p>I have a global variable named id. </p>

<p>When I call the function below id doesn't return the value of msg in less I use the bottom <code>alert('inside bottom4 (id) =' + id)</code>. If I comment out the alert, id is the value of the global variable before calling the function. </p>

<p>oh btw, <code>alert('after assignment=' + id);</code> has the correct return value.</p>

<hr>

<pre><code>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') &gt; 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)
}
</code></pre>
