This sample demonstrates a variety of ways to return data from the server into
the client page. The control supports Page Callbacks where the code in the browser
can callback onto the same page on the server and return the result from a method
call with fair support for typed result data via JSON encoding. This means you can
get result values such as integers, date time values, even objects and cursors returned
to you from the server. Cursors are marshalled to an object which contains an array of Rows and
proeprties for each of the fields.
Remote method calls are initiated by hooking an event - all the above are fired
off buttons and one onchange event on the listbox. These events then call the Proxy.callMethod()
function in the West Wind Client Library where Proxy is the id of the AjaxCallbackMethod
control on the page. A sample call looks like this:
Proxy.callMethod('Helloworld',[$("#txtName").val()],
function(result) {
alert("Returned: " + result);
},onPageError);
The first parameter is the method, followed by an array of arguments that are
marshalled to the server via JSON. Each value can be of any type and is
encoded into the appropriate JSON format. The server side control turns these
parameters into arguments to the method to be called. The final two parameters
are a callback handler that receives the result of a callback and an error handler.
Currently JSON marshalling is only supported from the server to the client. Any
parameters passed from the client to the server are passed as plain strings. The
problem is that FoxPro doesn't provide runtime type information, so there's no easy
way to marshal the parameter values to a proper type. There are a few options to
make this work, but in this initial release only raw string input parameters are
supported.
You also have access to POST data if you choose. The control lets you control how data is sent to the server. Method calls post parameters, but you can also optionally
have it send up all the form variables from the current clientstate. What's really
cool about this is that hte page framework automatically assigns these to the controls
of the page so in many cases you can reference - this.txtName.Text just as you would
with a full page postback! This may actually be the preferred way to return data
back to the client.