After trying long time I feel so bad, I still don’t understand how to use the jQuery/AJAX/JSON in the webserver. I have seen a lot of examples about jQuery/AJAX/JSON, I find that maybe the “AJAX XMLHttpRequest” is what I want. but how can I write a “AJAX XMLHttpRequest” for the webserver.
Because the webserver class is not written by myself, and the webserver is from WouterH’s example 186. I don’t understand all functions of the class and I can also not develop more functions on the basis of the weserver-class.
I think, if I use AJAX XMLHttpRequest for updating parts of a web page - without reloading the whole page, I need use the “HttpRequest.cs” file of the WouterH’s example 186. Becase there are “GET” and “POST” parameter in the class. My big problem is the codes, I don’t know how can I use the classes for my destination.
until now I have only finished the webserver as follow:
the webpage will be refreshed every 1 second completely.
using (HttpServer server = new HttpServer())
{
server.AddEvent("/", new HttpServer.EventCallback(index));
while (true)
{
// Sleep for 500 milliseconds
Thread.Sleep(500);
}
}
private static void index(object sender, HttpServer.EventCallbackEventArgs e)
{
string replace_string = Resources.GetString(Resources.StringResources.index);
...............................
..............................
// read the html file as a string, the parameter in the string will be replaced
// T1 to T8 are from my threadloop
string ready_string = stringreplace("~T1~", T1_String);
ready_string = stringreplace("~T2~", T2_String);
ready_string = stringreplace("~T3~", T3_String);
ready_string = stringreplace("~T4~", T4_String);
ready_string= stringreplace("~T5~", T5_String);
ready_string = stringreplace("~T6~", T6_String);
ready_string = stringreplace("~T7~", T7_String);
ready_string = stringreplace("~T8~", T8_String);
.............................................
.............................................
e.Response = ready_string;
e.ResponseContentType = "text/html";
}
index html file is as follow:
<html>
<head>
<title>ZAGmbH TVS Home</title>
<link rel="stylesheet" type="text/css" href="index_styling.css" />
<meta http-equiv="refresh" content="1" />
</head>
<body>
<h3>Temperaturinput Tabelle</h3>
<table border="0" cellpadding="2" cellspacing="0">
<tr><th>Temperatur Nr.</th><th>Temperatur Wert</th><th>Temperatur Nr.</th><th>Temperatur Wert</th></tr>
<tr><td class="label">T1:</td><td>~T1~</td><td class="label">T2:</td><td>~T2~</td></tr>
<tr><td class="label">T3:</td><td>~T3~</td><td class="label">T4:</td><td>~T4~</td></tr>
<tr><td class="label">T5:</td><td>~T5~</td><td class="label">T6:</td><td>~T6~</td></tr>
<tr><td class="label">T7:</td><td>~T7~</td><td class="label">T8:</td><td>~T8~</td></tr>
</table>
</body>
</html>
Can you give me some help, how can I use the “AJAX XMLHttpRequest” in this webserver?