This uses "fetch" followed by ".then" etc. etc. etc.
and is tuned to be a design pattern for future code
array_free(msglist);
// FIXME we still fail because we aren't finished yet
- do_404(h);
+ add_response_header(h, strdup("Content-type"), strdup("application/json"));
+ h->response_code = 200;
+ h->response_string = strdup("OK");
+ h->response_body = "{ \"one\":111 , \"two\":222 , \"three\":333 }";
+ h->response_body_length = strlen(h->response_body);
}
// RENDERER FOR THIS VIEW
function view_render_calendar() {
- document.getElementById("ctdl-main").innerHTML = `STUB RENDERER FOR CALENDAR ROOM`;
-
fetch(
"/ctdl/r/" + escapeHTMLURI(current_room) + "/calendar::"
)
- .then((response) => {
+ .then(response => {
if (response.ok) {
return(response.json());
}
+ else {
+ throw new Error(`${response.status} ${response.statusText}`);
+ }
})
- .then((j) => {
- console.log("Something");
+ .then(j => {
+ document.getElementById("ctdl-main").innerHTML = JSON.stringify(j);
})
- .catch((error) => {
- console.log("Error: " + error);
+ .catch(error => {
+ console.log(error);
+ document.getElementById("ctdl-main").innerHTML = `<div class="ctdl-fatal-error">${error}</div>`;
});
}