0
$('#leftmenu>li').on('click', function() {
    var sessionActive = "false";
    $.get("Session/Index/", function(data, status) {
        if (data.length > 0) {
            sessionActive = "true";
            alert(data.length);
        }
    });
    alert(sessionActive);
});

In the above javascript function, I don't understand why the value for sessionActive does not change to "true" when the length of data is greater than 0. In the alert(data.length); I see a positive number due to my test page (Session/Index) having data, but the second alert displays false, as if the assignment to true never happened. How can I get this to work?

Thank you.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
ITWorker
  • 965
  • 2
  • 16
  • 39
  • 2
    Please also indent proper. It was not clear that the $.get was inside the click – mplungjan Jul 12 '16 at 14:23
  • @squint: I see no reason to replace the one I used with a different one. Indeed, I see basically no reason for that more-recent question vs. the earlier one. – T.J. Crowder Jul 12 '16 at 14:25
  • @T.J.Crowder - actually he did not return sessionActive, only modified it – mplungjan Jul 12 '16 at 14:25
  • @T.J.Crowder: He's not returning anything. –  Jul 12 '16 at 14:26
  • @squint: It really doesn't matter, the question still gets answered there. – T.J. Crowder Jul 12 '16 at 14:26
  • 1
    @mplungjan: I reopened it and then closed it. –  Jul 12 '16 at 14:26
  • 1
    @T.J.Crowder: Eliminates a potential point of confusion for someone already confused by the problem. –  Jul 12 '16 at 14:27
  • 1
    @squint: Meh. :-) But no biggie. I'm just not a fan of manufactured "canonical" questions posted after real ones that could be turned into canonical ones instead. But hey, I fairly routinely don't get my way. :-) – T.J. Crowder Jul 12 '16 at 14:29

0 Answers0