AJAX get problem with varible

AJAX get problem with varible

Hello,
I would like to ask you how to get the value of variable "data".
This not working:
  1.  ...   
  2.     else if (field == 'username')
        {
            $.get("register.php", {check: content1},
            function(data)
            {
               if (data == 'ok') {ok = 1;} else {ok = 2;}
            });
        }






  3.   ...
And this working, but I don't want any alert.
  1.   ...
  2.     else if (field == 'username')
        {
            $.get("register.php", {check: content1},
            function(data)
            {
               if (data == 'ok') {ok = 1;} else {ok = 2;}
            });
            alert('');
        }







  3.   ...
Thank you very much for your help!