Dustin's API Test

Change class name on click in jQuery

HTML

<div id="banner-message">
  <button>Call Dustin's API</button>
</div>

CSS

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

#banner-message {
  background: #fff;
  border-radius: 4px;
  padding: 20px;
  font-size: 25px;
  text-align: center;
  transition: all 0.2s;
  margin: 0 auto;
  width: 300px;
}

button {
  background: #0084ff;
  border: none;
  border-radius: 5px;
  padding: 8px 14px;
  font-size: 15px;
  color: #fff;
}

#banner-message.alt {
  background: #0084ff;
  color: #fff;
  margin-top: 40px;
  width: 200px;
}

#banner-message.alt button {
  background: #fff;
  color: #000;
}

JavaScript

// find elements
var banner = $("#banner-message")
var button = $("button")

// handle click and add class
button.on("click", function(){
  				window.$.ajax({
					method: 'GET',
					url: 'http://localhost:53650/code/17752040979',
					contentType: 'text/plain',
					beforeSend: function(xhr) {
						xhr.setRequestHeader('Authorization', 'Basic MmNjZjFmMmQ3ZmU4YWFmOGVmOTI2NDM5YjYyOGY4MmE6ZWQ1YzFkNzA3ZTY0OGEwMDdiMGI0YTZkMDU1MjY2ZTg=');
					},
					xhrFields: {
						// The 'xhrFields' property sets additional fields on the XMLHttpRequest.
						// This can be used to set the 'withCredentials' property.
						// Set the value to 'true' if you'd like to pass cookies to the server.
						// If this is enabled, your server must respond with the header
						// 'Access-Control-Allow-Credentials: true'.
						withCredentials: false
					},          
				}).done(function(msg) {
					alert('Data Saved: ' + msg);
				}).fail(function(jqXHR, textStatus) {
					alert('Error: ' + textStatus);
				});
});