Linb,
I have created a bit of documentation for myself on the usage of linb.SAjax to communicate with a server (for example node.js). As this documentation can be useful for others, I am posting it here, just my small contribution to your product.
How to send and receive data from a server using linb.SAjax() (linb4.0) linb.SAjax sends (at the end of the url string, separated by a '?' character) the request fields you have sent in the second parameter of linb.SAjax and adds an extra field called "
callback".
The
value of that callback field is the
name of a function inside linb that should be used to return the JSON values as the only parameter for that function.
Example: you send this request from LINB:
linb.SAjax('
http://localhost:3333/bla', {'get':'whatever','xmit':'nonsense'}
, function(response, respType, threadId){
linb.log('@onSuccess: RespType='+respType+' Response='+response);
var sData= response.field1; // for example server is returning {field1='whatever', 'field2'=1234}
ns.ctl_input2.setValue(sData, true); // assume you have an input field named ctl_input2
}, function(response, respType, threadId){
linb.log('@onFail : RespType='+respType+' Response='+response);
ns.ctl_input2.setValue("some **ERROR*** receiving serverdata", true);
}).start();
Linb will send the following request string via HTTP:
GET http://localhost:3333/bla?get=whatever&xmit=nonsense&callback=linb.SAjax.NO._1 HTTP/1.1You see there the extra field
callback that was automatically added by LINB.
Now when the server returns the data as a reply to this request, it should build a string
as follows:
<valueOfTheCallbackField>(<stringContainingJsonObjectData>)Note: the symbols "<" and ">" are just meant to identify concepts, they are not part of the string to return. Suppose the server is returning the following JSON string: {field1='whatever', 'field2'=1234}
Now on the server we build the return string, for example in javascript if we are using a javascript server like node.js
var valueofCallbackField= "linb.SAjax.NO._1"; // could be obtained as for example
// var valueofCallbackField= httpRequest.callback
var jsonString= "{'field1'='whatever', 'field2'=98765}"; // the data the server is sending back to the client
var returnData= valueofCallbackField + "(" + jsonString + ")" ; // the "(" and ")" brackets are needed to define a function.
You can see in the bit of LINB code used to make the request using linb.SAjax (see above) how the value of the returned field
field1 can be obtained from the returned JSON string.