jQuery addClass example

Change class name on click in jQuery

by kneidels

CSS

body {
  background: #20262E;
  padding: 20px;
  font-family: Helvetica;
}

JavaScript

var tokenViaApp = 'jrfvbj86tvbj'; //this is my token

console.log('Our token is:' + tokenViaApp);
console.log('Step 1, starting to run.');

(tokenViaApp === '' ? Promise.resolve() : saveTokenToUser(tokenViaApp))
    .then(() => {
        // Do the redirect
    		console.log('we have resolved the Promise and completed the function');
    })
    .catch(error => {
        // Handle/report error
        console.log('did ajax fail?');
    });
    console.log('We\'re continuing to process scripts on the page');
		alert("all done, see console");

async function saveTokenToUser(token) {
        console.log('Entered function');
        await $.ajax({ 
          type: "POST", 
         // async: false,
          url: "/echo/html/", 
          data: {
              t: token
          }, 
          success: function(msg) {  
               localStorage.token_origin = 'app';
               console.log('ajax call successful, saved to localStorage');
          },
          fail: function(xhr, textStatus, errorThrown){
       				console.log('ajax request failed');
   				 }
        });
}