jquery ajax to channel api

jquery ajax to channel api

by Simon060694

HTML

<div id="banner-message">
  <p>Hello World</p>
  <button>Check 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", () => {
 var settings = {
  "url": "https://api.r4m.work/util//chat/channel",
  "method": "POST",
  "timeout": 0,
  "headers": {
    "Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6Ijg5ZWNiMTkyMyJ9.eyJleHAiOjE1OTczMDczOTIsImlhdCI6MTU5NzMwMzc5MiwiaXNzIjoicml2aWVyYTRtZWRpYS5jb20iLCJzdWIiOiI4ZTIwMzczNC1lOGRiLTQ3NjAtYjg4NS1jYmE2ZDRlNmNjYjciLCJhdXRoZW50aWNhdGlvblR5cGUiOiJQQVNTV09SRCIsImVtYWlsIjoiYWRtaW5Acml2aWVyYTRtZWRpYS5jb20iLCJlbWFpbF92ZXJpZmllZCI6dHJ1ZSwicHJlZmVycmVkX3VzZXJuYW1lIjoiYWRtaW4tdXNlciJ9.ihmT77jTQphrsg1EpQEh796J5B9-ohZpefn6zZWQXR0",
    "Content-Type": "application/json"
  },
  "data": JSON.stringify({"name":"member test channel"}),
};

$.ajax(settings).done(function (response) {
  console.log(response);
}).catch(function (response) {
  console.log(response);
});;
})