Unreasonable behavior when dealing with variables ouside the callback.

Unreasonable behavior when dealing with variables ouside the callback.

  1. var repeat = 1;

    function RefreshPage()
    {
        $.post("php/getchatmsg.php", function(data) {
            repeat = 0;
        });
        alert(repeat);
    }







      This code will alert the value 1 on the first time the function RefreshPage() is run, but will output 0 on the rest of the calls, furthermore this code:

  1. var repeat = 1;

    function RefreshPage()
    {
        while (repeat == 1)
        {
            $.post("php/getchatmsg.php", function(data) {
                repeat = 0;
            });
        }
    }









just makes my browser crash UNLESS I add an alert after the post inside the loop...

I'm sorry, but what the fuck?

Any ideas? Any help will be appreciated. Thank you in advance.