The script below gets the json result I have provided at the bottom of this post. Once the token has been retrieved it will be stored via the data() method. Though for some reason the token is not being passed beyond the ajax() call for some reason. I was wondering if you see a mistake in my code or with the json result below where the code is not passing the token not to other methods below the ajax() call that retrieves the token from the auth server?

Here is the javascript that retrieves the token:
Code:
    $(function() {
    var request = $.ajax({
    type: "GET",
    cache: false,
    data: {v: 1, r: 'requestToken', apikey: 'root', secret: 'root'},
    url: "/vdesktop/deskapi/",
    dataType: "json",
    });
    request.done(function(data) {
    if (data.statusCode == 1) {
    $token = data.response;
    $(document.body).data("token", data.response);
    } else{
    alert("Error: ("+data.statusCode+") "+data.response);
    }
    });
    request.fail(function(jqXHR, textStatus) {
    alert("Error: "+textStatus);
    });
    alert($(document.body).data("token"));
    });
here is a json result from the auth server (so you can test if you want):
Code:
{"statusCode": 1, "response": "1fa8997a0cb5062144b25c1ff917a5f293bee88b62cd4f99aca26fda12515372" }