Class wwAjaxMethodCallback

The wwAjaxMethodCallback class lets client side JavaScript code call FoxPro server side methods on objects and return the result as JSON enabled objects.

This simple mechanism provides an easy to use and efficient mechanism for JavaScript code to use the FoxPro server application as a data server that executes logic and then returns results to the client. JSON encoding of the result data allows for complex data to be returned from the server which includes simple types, simple and complex objects, FoxPro cursors (represented as object arrays), and arrays.

This class is mapped to the client side wwAjaxMethodCallback class which is automated by the server control to perform the client side callbacks.

To initiate a client side callback to the server:

<ww:wwAjaxMethodCallback ID="Proxy" runat="server" 
                        PostBackMode="Post"
                        PostBackFormName="form1"
                        ScriptLocationType="WebResource"  
                        AllowedPageMethods="Helloworld,AddNumbers,GetDeveloperList,GetDeveloper,SaveDeveloper">
</ww:wwAjaxMethodCallback>

Client side code can then call server methods with Proxy.callMethod where Proxy is the ID of the control:

<script type="text/javascript">
    function HelloWorld()
    {
        Proxy.callMethod('HelloWorld',[document.getElementById('txtSayHello').value],Helloworld_Callback,OnError)
    }
    function Helloworld_Callback(Result)
    {
        // *** Update element in the document with jQuery
        $('lblHelloWorldResult').html(Result);
    }
</script>

On the server side the implementation simply implements the Helloworld method (and any others) on the form as methods. The default target object is the Web Control Page the control lives on, but optionally the control allows routing requests to any other object via the TargetObject property.

Callbacks handled by this control can return also JSONP responses by specifying a callback= query string parameter. You can use $.getJSON("ajaxrequest.wwd?callback=?") which jQuery to return remote data for example.

Use and Operation

Remarks

Please be aware that when making method callbacks OnInit() and OnLoad() events are fired both on the form and the control. If you have code in the page's OnInit() or OnLoad() use this.Page.CallbackControl.IsCallback to exit early if desired.

If you use this control from a user control and you want to route the callback handling code to a method in the user control you have to explcitly assign the TargetObject to the control in the OnInit():

*** In a User Control use code like this to route User Control methods
FUNCTION OnInit()
this.HeaderProxy.TargetObject = this
DODEFAULT()
RETURN

Class Members

MemberDescription

OnError

Allows capturing of errors that occur during callback method processing, since callback method errors are independently handled inside of a TRY/CATCH.

AllowedPageMethods

Specify a comma delimited list of methods you allow to be called remotely. Leave blank to allow any method (not recommended)

PostBackFormName

The name of the form used for PostBack. If blank defaults to Forms[0]

PostBackMode

PostMethodParametersOnly, Get, Post, PostNoViewState

ScriptLocation

Location of the script file: WebResource, EmbeddedInPage or relative URL (~/images/wwScriptLibrary.js)

ServerUrl

The URL to post back to. Leave blank for the current page

TargetObject

The object on which methods are called. Defaults to the Page.

Requirements

Assembly: webcontrolsjquery.prg

See also:

Client Class AjaxMethodCallback | Remote AJAX Method Calls using JSON Serialization

© West Wind Technologies, 1996-2024 • Updated: 01/20/14
Comment or report problem with topic