Your example work fine, but see this escenario:
I put the html content of the guessmynumber example in the handle resp.Write and it did show the page, but I cann't read the fields of this form because when I did press the guess button not action is triggered, seems than that is not readed. This is my code:
Sub AppStart (Args() As String)
srvr.Initialize("srvr")
srvr.Port = 51042
srvr.AddHandler("/index.html", "GuessMyNumber", False)
srvr.Start
StartMessageLoop
'open browser and navigate to:
http://127.0.0.1:51042/index.html
End Sub
-------------------
class module / Server Handler / GuessMyNumber
-------------------
Sub Handle(req As ServletRequest, resp As ServletResponse)
Try
If req.GetSession.HasAttribute("myNumber") = False Then
req.GetSession.SetAttribute("myNumber", Rnd(0, 101))
End If
Dim myNumber As Int = req.GetSession.GetAttribute("myNumber")
Dim n As String = req.GetParameter("number")
If IsNumber(n) = False Then
resp.Write("Please enter a valid number.")
Else
If n > myNumber Then
resp.Write("My number is smaller.")
Else If n < myNumber Then
resp.Write("My number is larger.")
Else
resp.Write("Well done!!!")
End If
End If
Catch
resp.SendError(500, "error....")
End Try
resp.Write($"
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "
http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta content="text/html; charset=UTF8" http-equiv="content-type">
<title>Guess My Number</title>
<script src="
https://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<style>
html {
height: 100%;
}
body {
height: 100%;
background-repeat: no-repeat;
background-attachment: fixed;
background: #f0f9ff; /* Old browsers */
background: -moz-linear-gradient(top, #f0f9ff 0%, #cbebff 47%, #a1dbff 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#f0f9ff), color-stop(47%,#cbebff), color-stop(100%,#a1dbff)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #f0f9ff 0%,#cbebff 47%,#a1dbff 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #f0f9ff 0%,#cbebff 47%,#a1dbff 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #f0f9ff 0%,#cbebff 47%,#a1dbff 100%); /* IE10+ */
background: linear-gradient(to bottom, #f0f9ff 0%,#cbebff 47%,#a1dbff 100%); /* W3C */
}
</style>
</head>
<body>
<h1>Guess My Number</h1>
Enter number: <input type="text" id="txtNumber"></input>
<button type="button" id="btnGuess">Guess!</button><br/><br/>
<button type="button" id="btnReset">Reset secret number</button><br/>
<p id="result"></p>
<script type="text/javascript">
$("#btnGuess").click(function(){
$.post("guess", "number=" + txtNumber.value,
function(data) {
$("#result").html(data);
$("#txtNumber").focus();
$("#txtNumber").select();
}
);
});
$("#txtNumber").keyup(function(event){
if(event.keyCode == 13){
$("#btnGuess").click();
}
} );
$("#btnReset").click(function(){
$.post("reset");
});
</script>
<p>
The time now is ${DateTime.Time(DateTime.Now)}
</p>
</body>
</html>
"$)
End Sub
Thank you for your help.