-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathback.js
More file actions
37 lines (27 loc) · 976 Bytes
/
back.js
File metadata and controls
37 lines (27 loc) · 976 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
function processa_back() {
console.log("passei")
let option = document.getElementById('option').value
let url = "https://excuser.herokuapp.com/v1/excuse/"
if (option != "random"){
url += option
}
console.log(option)
console.log(url)
let ajax = new XMLHttpRequest()
ajax.open('GET', url)
ajax.onreadystatechange = () => {
if(ajax.readyState == 4 && ajax.status == 200) {
let respostaJson = ajax.responseText
let respostaObj = JSON.parse(respostaJson)
console.log(respostaObj[0].excuse)
document.getElementById('textarea').innerHTML = respostaObj[0].excuse
}
if(ajax.readyState == 4 && ajax.status == 404) {
document.getElementById('textarea').innerHTML = 'ststuas da requisição' + ajax.status
}
}
ajax.send()
}
function teste() {
console.log('passei no teste')
}