Skip to content

Instantly share code, notes, and snippets.

@higordiego
Created April 5, 2024 12:32
Show Gist options
  • Save higordiego/4abeff5d96d8905af2b5eee6b204b360 to your computer and use it in GitHub Desktop.
Save higordiego/4abeff5d96d8905af2b5eee6b204b360 to your computer and use it in GitHub Desktop.
<!DOCTYPE >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Pergunta chat.</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
</head>
<body class="container" style="margin-top: 5%">
<div class="form-group">
<label for="texto">Faça sua pergunta abaixo.</label>
<input type="text" class="form-control" type="text" id="texto" name="texto" aria-describedby="emailHelp" placeholder="Qual seria a sua dúvida ?">
</div>
<button onclick="buscarTexto()" style="margin-left: 91%;" id='button-submit' class="btn btn-primary">Pesquisar</button>
<div id="resultado" style="margin-top: 5%;"></div>
<script>
async function buscarTexto() {
var texto = document.getElementById('texto').value;
console.log('texto', texto)
document.getElementById('resultado').innerHTML = "Processando...";
document.getElementById("button-submit").disabled = true;
const response = await fetch('/resposta', {
method: "POST",
mode: "cors",
cache: "no-cache",
credentials: "same-origin",
headers: {
"Content-Type": "application/json",
},
redirect: "follow", // manual, *follow, error
referrerPolicy: "no-referrer", // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
body: JSON.stringify({ consulta: texto }), // body data type must match "Content-Type" header
});
const { resposta } = await response.json(); // parses JSON response into native JavaScript objects
document.getElementById('resultado').innerHTML = `<hr><br>Resposta: <h3><strong>${resposta} </strong> </h3>`;
document.getElementById("button-submit").disabled = false;
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment