fetch demo js
var token;
fetch("/login", {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
body: "tel=15528801837&password=1"
}).then(function(res) {
if (res.ok) {
token = res.headers.get("x-auth-token");
res.json().then(function(data){
console.debug(data);
});
} else if (res.status == 401) {
alert("Oops! You are not authorized.");
}
}, function(e) {
alert("Error submitting form!");
});
fetch("/api/area/search/parentId?pid=0",{
headers: {
"x-auth-token": token
}
}).then(function(response) {
return response.json();
}).then(function(data) {
areas = data._embedded.areas;
for(i=0;i < areas.length; i++){
console.debug(areas[i].areaName);
}
}).catch(function(e) {
console.debug(e);
});