Skip to content

Commit

Permalink
verify id before make the request
Browse files Browse the repository at this point in the history
  • Loading branch information
kikeelectronico committed Jul 27, 2024
1 parent 12560c3 commit fe05205
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions front/src/components/pages/Info.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,37 @@ function Info() {
useEffect(() => setId(window.location.pathname.split('/')[3]), [])

useEffect(() => {
var dev = new XMLHttpRequest();
dev.onload = function (e) {
if (dev.readyState === 4) {
if (dev.status === 200) {
var data = JSON.parse(dev.responseText);
setDevice(data)
} else {
console.error(dev.statusText);
if (id !== "") {
var dev = new XMLHttpRequest();
dev.onload = function (e) {
if (dev.readyState === 4) {
if (dev.status === 200) {
var data = JSON.parse(dev.responseText);
setDevice(data)
} else {
console.error(dev.statusText);
}
}
}
}
dev.open("GET", root + "api/devices/get/" + id + "/");
dev.setRequestHeader('authorization', 'baerer ' + getCookieValue('token'))
dev.send();
dev.open("GET", root + "api/devices/get/" + id + "/");
dev.setRequestHeader('authorization', 'baerer ' + getCookieValue('token'))
dev.send();

var sta = new XMLHttpRequest();
sta.onload = function (e) {
if (sta.readyState === 4) {
if (sta.status === 200) {
var data = JSON.parse(sta.responseText);
setStatus(data)
} else {
console.error(sta.statusText);
var sta = new XMLHttpRequest();
sta.onload = function (e) {
if (sta.readyState === 4) {
if (sta.status === 200) {
var data = JSON.parse(sta.responseText);
setStatus(data)
} else {
console.error(sta.statusText);
}
}
}
sta.open("GET", root + "api/status/get/" + id + "/");
sta.setRequestHeader('authorization', 'baerer ' + getCookieValue('token'))
sta.send();
}
sta.open("GET", root + "api/status/get/" + id + "/");
sta.setRequestHeader('authorization', 'baerer ' + getCookieValue('token'))
sta.send();
}, [id])

return (
Expand Down

0 comments on commit fe05205

Please sign in to comment.