@sergeos
I've modified your HTML a bit to use Jquery for AJAX and modifying the DOM. I'm just familiar with it, so it was easier for me to create the demo. Feel free to substitute your favourite framework or just use vanilla JS if you prefer.
To start, save the following HTML to you web app root folder as "tableaddtest.html":
Then add the following code to the CApp class (somewhere after the If po_Helpers.Regex.Test(po_Req.Url(urlsection_Path), "^showcase/[0-9]+$", False) Then showcase code section:Code:<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" /> <title>Aligning Buttons</title> </head> <body> <h1 style="color:green;text-align:center;">NumberSender</h1> <div class="container"> <div id='buttons' class="text-left"> <button type="button">1</button> <button type="button">2</button> <button type="button">3</button> <button type="button">4</button> <button type="button">5</button> <button type="button">6</button> </div> <table id='mytable' width="500" border="1"> <tr> <th>ROW #</th> <th>COLOR #</th> </tr> <tr> <td>ROW 1</td> <td bgcolor="red">COLOR 2</td> </tr> <tr> <td>ROW 2</td> <td bgcolor="green">COLOR 5</td> </tr> </table> </div> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script> <script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script> <script> // Hook each # button's click event. $('#buttons button').click(function() { // # button clicked var number = $(this).text(); // Send AJAX query to the server at /numberreceiver/<number> $.ajax({ url: "/numberreceiver/" + number, }) .done(function( json ) { // Add a row to the table using the JSON response from the server json = $.parseJSON(json); var markup = "<tr><td>ROW " + ($('#mytable tr').length) + "</td><td bgcolor=" + json.bgcolor + ">COLOR " + number + "</td><</tr>"; $("#mytable").append(markup); if ( json.status != 200 ) { alert('Error #' + json.status + ': ' + json.errormessage); } }); }); </script> </body> </html>
Finally, start the app server and navigate to http://127.0.0.1:8080/tableaddtest.html and try clicking some buttons. You should see something like this:Code:ElseIf po_Helpers.Regex.Test(po_Req.Url(urlsection_Path), "^numberreceiver/[0-9]+$", False) Then ' Build JSON response ' JSON helper methods are forthcoming, ' but for now we'll have to use the ComplexResponse and manually add an "Content-Type: application/json" header With po_Response.ComplexResponse .AddHeaderEntry "Content-Type", "application/json" Set lo_Json = New_C.JSONObject With lo_Json .Prop("status") = 200 ' Get the color index # from the end of the URL path .Prop("number") = Split(po_Req.Url(urlsection_Path), "/")(1) Select Case .Prop("number") Case 1 .Prop("bgcolor") = "purple" Case 2 .Prop("bgcolor") = "red" Case 3 .Prop("bgcolor") = "blue" Case 4 .Prop("bgcolor") = "yellow" Case 5 .Prop("bgcolor") = "green" Case Else ' Uhoh! Unknown color index .Prop("status") = 500 .Prop("errormessage") = "Unknown color index #" & .Prop("number") .Prop("bgcolor") = "gray" End Select End With .SetResponseDataBytes lo_Json.SerializeToJSONUTF8 End With
Until you click #6, then you will see a simulated error:
I hope the code and comments are enough to demonstrate how this type of thing can be done, but let me know if you have any questions.




Reply With Quote