LoginSignup
0
0

More than 1 year has passed since last update.

plunkerで「chaplus api」

Last updated at Posted at 2022-08-24

概要

plunkerで「chaplus api」叩いてみた。
練習問題やってみた。

練習問題

人工無脳とchatせよ。

写真

image.png

サンプルコード

var endpoint = "https://ohiapp0.herokuapp.com/chaplus?q=";

function send(msg) {
	var xhr = new XMLHttpRequest();
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4 && xhr.status == 200)
		{
			showMessage(xhr.responseText);
		}
		else
		{
			//alert(xhr.readyState);
			//alert(xhr.status);
			//alert(xhr.responseText);
		}
	};
  var uri = endpoint + msg;
	xhr.open("GET", uri, true);
	xhr.send();
	//alert("ok");
}

document.forms.publish.onsubmit = function() {
  let outgoingMessage = this.message.value;
  showMessage(outgoingMessage);
  send(outgoingMessage);
  this.message.value = '';
  return false;
};

function showMessage(message) {
  let messageElem = document.createElement('div');
  messageElem.textContent = message;
  document.getElementById('messages').appendChild(messageElem);
}
showMessage("start");



フロー

image.png

成果物

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0