简体   繁体   中英

Can't alert javascript variable

I'm trying to print the contents of my digest variable but not having any luck. The below is the code I have. I've read a few tutorials and can't see why it wouldn't work.

  // Store Credentials
  var userName = "username";
  var sharedSecret = "secret";

  // Build Header
    var date = new Date();
    var nonce = md5(Math.random());
    var nonce_ts = date.toISOString().replace(/(\.\d\d\dZ)/ ,'Z');
    var digest = (new Buffer(sha1(nonce + nonce_ts + sharedSecret)).toString('base64'));

  alert(digest);

It was taken from nodeJS and I am trying to make it javascript.

It was taken from nodeJS and I am trying to make it JavaScript.

Then you need to make sure md5 , sha1 and Buffer are ported over to your JavaScript environment. These aren't normally available in a browser.

The reason you're not getting an alert window, is because the code is crashing on those function. You can easily see that by opening your browser's developer console (Usually F12)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM