From 48c8b070fcd47a26f874f34e2474731dcda374f4 Mon Sep 17 00:00:00 2001 From: Georg Hopp Date: Sat, 3 Mar 2012 09:35:12 +0100 Subject: [PATCH] changed ajax to get json and integrate a javascript countdown. --- src/http/response/me.c | 37 +++++++++++++++++++++++++++++++++---- src/http/response/randval.c | 17 +++++++---------- 2 files changed, 40 insertions(+), 14 deletions(-) diff --git a/src/http/response/me.c b/src/http/response/me.c index 62fd138..857de55 100644 --- a/src/http/response/me.c +++ b/src/http/response/me.c @@ -45,7 +45,6 @@ "left: 200px;" \ "top: 100px;" \ "position: fixed;" \ - "overflow: none;" \ "background-color: white;" \ "border: 1px solid black;" \ "}" \ @@ -59,23 +58,53 @@ "" \ "" \ "" \ "" \ - "
" \ + "
" \ + "" \ + "Value created at:

" \ + "Next value in:
" \ + "
" \ + "Value: " \ + "
" \ "
" \ "

Testpage

" \ "" \ - "
Link" \ + "
Link" \ "
" \ + "
" \ "" \ "" diff --git a/src/http/response/randval.c b/src/http/response/randval.c index e11c128..5530127 100644 --- a/src/http/response/randval.c +++ b/src/http/response/randval.c @@ -33,9 +33,10 @@ #include "http/message.h" #include "http/header.h" -#define RESP_DATA "" \ - "Value created at:
%s
Next value in: %ld seconds
" \ - "
Value: %02d" +//#define RESP_DATA "" \ +// "Value created at:
%s
Next value in: %ld seconds
" \ +// "
Value: %02d" +#define RESP_DATA "{\"ctime\":%ld,\"vnext\":%ld,\"value\":%02d}" HttpResponse httpResponseRandval(time_t ctime, int value) @@ -45,7 +46,6 @@ httpResponseRandval(time_t ctime, int value) HttpResponse response; HttpMessage message; size_t nbuf; - struct tm * tmp; time_t remaining; response = new(HttpResponse, "HTTP/1.1", 200, "OK"); @@ -55,17 +55,14 @@ httpResponseRandval(time_t ctime, int value) new(HttpHeader, "Content-Type", sizeof("Content-Type")-1, - "text/html", - sizeof("text/html")-1)); + "application/json", + sizeof("application/json")-1)); message->type = HTTP_MESSAGE_BUFFERED; - tmp = localtime(&ctime); - nbuf = strftime(timebuf, sizeof(timebuf), "%a, %d %b %Y %T %Z", tmp); - remaining = 30 - (time(NULL) - ctime); - nbuf = sprintf(buffer, RESP_DATA, timebuf, remaining, value); + nbuf = sprintf(buffer, RESP_DATA, ctime, remaining, value); message->nbody = nbuf; message->body = malloc(nbuf);