DomAPI uses a form of remote-scripting for achieving remote procedure calls. Remote-scripting was chosen as the protocol based on a number of factors including browser support, platform support and ease of use.
This event fires after the engine receives a packet from the server. The packet received is passed as the single parameter.
another way to deal with this event is to pass a "handler" function to sendPacket(). Both are legitimate uses. You are free to use either method or both.
This event fires when a packet is dispatched to the server. You can analyze the packet (which is passed as the only parameter) to determine what it contained. Each packet created has a unique guid, which can be used to track it's progress through the engine via the onsend() and onreceive() events.
Example:
domapi.rpc.onreceive = function(packet){
if(packet.guid == "GUID_3")alert("Order data sent to server for processing");
};
This method is called by the server code. You do not call it from your client code.
If you would like to interact with the receivePacket() method, see the onreceive() event.
The "arg" parameter fed to this method is an inline Object. See below for accepted parameters. Any parameters not listed here that you add may also be attached to any returned Object.
This places the passed packet in the send queue. If no other packets were in the queue, it is dispatched immediately, otherwise packets are dispatched on a first-come-first-serve basis. sendPacket() also accepts an optional handler function. This handler will be fired when the sent packet returns from the server. The incoming packet is also passed to this handler. Handlers are matched to packets by the packet id so it is very important that your server code pass the sent id back in the response packet.
Example:
var myPacket = new RPCPacket("newCust.cgi/add","Saving new customer");
myPacket.loadFromForm(document.custForm);
myPacket.data.add("cust_added",new Date());
domapi.rpc.sendPacket({
packet : myPacket,
onreceive : custAdded //custAdded called on success
});
Available "arg" Parameters:
Parameter
Type
Required
Default
Description
packet
RPCPacket
Y
onreceive
Function
Function call when response is received. The returned packet is passed to it. The domapi.rpc.onreceive event is still fired.
timeout
integer
core.rpc.timeout
Allows you to override the default timeout.
ontimeout
Function
Allows you to provide a custom ontimeout handler. domapi.rpc.ontimeout is still called.
When true, the engine will display urls it is about to use. It also will not hide the normally hidden IFRAME.
Note that this IFRAME is not created until after the first call to sendPacket().