B4J Question [BANanoServer] Executing ws.b4jSend

Mashiane

Expert
Licensed User
Longtime User
Hi there

Following on the BANano Essentials Ebook, my BrowserIndex and ServerIndex code has been updated to use ws.B4JSend.

For example, in my BrowserIndex, I have

B4X:
...
ws.B4JSend("DirectMySQLOnServer_BAN", payload)
...

and inside the ServerIndex.DirectMySQLOnServer_BAN sub, I am calling db related functions.

For example..

B4X:
...
Dim doit As ResumableSub = dDB.SQLRunQuery(query, args)
Wait For(doit) Complete (Result As Boolean)
...

My code is working very well, however I just need to confirm if what Im doing is not abnormal and might cause unexpected bahaviour.

Thanks in advance.
 

nedium

Active Member
Licensed User
Longtime User
Button_Click:
ws.B4JSend("Suma_BAN", CreateMap("counter": 5))

--------------

In 'BROWSERTemplate':
Public Sub dato(ss As Int)
    WelcomeModalMessage.Text = "suma " & ss   
    WelcomeModal.Open
End Sub

-------------------

In 'SERVERTemplate':
public Sub Suma_BAN(params As Map)
    Dim n1 As Int = params.Get("counter")
    Dim suma As Int = n1 + 10
    ws.RunFunctionWithResult("dato",Array(suma))
    ws.Flush
End Sub

-----------------------------------------------

I don't know if I'm doing things right, I'm really trying to find a way to communicate both sides and then include other methods and show results on the page.

Thank you very much for the help
 
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
Do you get errors, either in the B4J log or in the Browsers console (F12)? I tried your code and I got the dialog popping up:

1653915209005.png
 
Upvote 0

nedium

Active Member
Licensed User
Longtime User
Hi,

Yes, you are right, I had an error in the console, it was pointing to another port, I am going to do tests to practice how to show data from the server to the page, if I have any other questions I will ask.

thank you very much for your help
 
Upvote 0
Top