B4J Question Webserver with jrdc response.

walmo

Active Member
Licensed User
Longtime User
Hi

I am trying to show data on webpage that is loaded after user login.
Every thing is working data is loaded in webserver but i cant get the data to show on page ,exept if i load another web page.
It is like the webpage can not wait for data request.

B4X:
Sub Handle(req As ServletRequest, resp As ServletResponse)
    mreq = req
    mresp = resp
    resp.ContentType = "text/html"
    Log(Main.PrintAllParameters(req))
    If req.GetParameter("ajax") = True Then
        Dim id As String = req.GetParameter("client_id")
        Wait For(Main.get_device(id)) Complete(result As Map)'command to sql query '
        resp.Write(result.GetKeyAt(1))
    End If
   
End Sub

And here is sql query
B4X:
Public Sub get_device (id As String) As ResumableSub
    Dim device_map As Map
    device_map.Initialize
    Dim req1 As DBRequestManager = CreateRequest
    Dim cmd As DBCommand = CreateCommand("app_devices", Array(id))
    Wait For (req1.ExecuteQuery(cmd, 0, Null)) JobDone(j1 As HttpJob)
    If j1.Success Then
        req1.HandleJobAsync(j1, "req1")
        Wait For (req1) req1_Result(res As DBResult)
        'work with result
        req1.PrintTable(res)
        For Each row() As Object In res.Rows
            Dim mac As String = (row(res.Columns.Get("mac")))
            device_map.Put("mac",mac)      
        Next
        j1.Release
       
    End If
    Return device_map
End Sub

And here is html
HTML:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
</head>
<body>
    <h1>Device List</h1>
    <img src='images/logo.png'/ width=100 height=100><br/>
    <div id="main">
        <FORM id = "form1" action="" method="post">
            <P>
                <LABEL for="id">Client Number: </LABEL>
                          <INPUT type="text" name="client_id"><BR>
                <input type="hidden" name="ajax" value="true"/>
                <INPUT type="submit" value="Send">
            </P>
        </FORM>
    </div>
    <script type="text/javascript">
    $("#form1").submit(function() {
    $.ajax({
           type: "POST",
           url: "/modems",
           data: $("#form1").serialize(),
           success: function(result)
           {
               $("#main").html(result);
           },
            error: function (xhr, ajaxOptions , thrownError) {
                alert(thrownError);
            }
         });

    return false;
});
    </script>
</body>

Thank you
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…