cj.ajax

The ajax object has methods to simplify common ajax calls and provide a framework to simplify interaction with server-side methods.

For instance, to display a current list of visitors you could:

Write the code yourself - create an addon that the content manager could drop on any page. The addon includes an ajax call back to the server for data. Then create a remote method (addon) that responds to the request with the data formatted appropriately.

Use cj.ajax - Within your same page addon, call the createRemoteQuery() method with the query needed on your page. Then do your ajax call with cj.ajax.data(). It runs your query and returns a javascript object with your data in a simple results object.

cj.ajax.data

Arguments

handler - the javascript function (event handler) to be called when the ajax call returns. The response from the ajax call is passed to the handler as it's single argument. For example, if your handler is

function myHandler( resultSet ) {}

then the handler would be 'myHandler'

queryKey - a string that uniquely identifies the query record in the Remote Query content. If you need to run a query on a client-side event, you can create the query in the Remote Query content table and add a unique key to the record. To execute this query, include the key in the queryKey argument of this call. To programmatically create a query and get a key, see the Contensive webclient reference, GetAjaxQueryKey method.

args - A list of arguments to be passed to the server for processing with the query. They are in 'name=value&name=value' format. Each name and each value must be individually escaped before assembling the string. Depending on the QueryType setup for this key, the args can be used differently.

QueryType argument setup in the Remote Query content table:

SQLQuery - args are replacement name=value pairs

ContentInsert - args are fieldname=value pairs, but all fieldnames must be in the fieldnamelist

ContentUpdate - args are fieldname=value pairs, but all fieldnames must be in the fieldnamelist

pageSize - records to be returned

pageNumber - the page where the records begin

responseFormat

"table" - Google Visualization formatWhen the hander is called, the single argument will be a javascript object with rows and columns. The row labels are accessed by the 'id' property of each row. For example, if your hander is:

myHander( results ) {

rows[0].id='fieldname'

rows[0].c[0].v='value'

"namearray" - returns arrays named for each field

dataadded[0]='value'

name[0]='value'

"namevalue" - returns only the first row of a table, with no arrays

dateadded='value'

ajaxMethod - the method used for this query

"data" - use the remote query table as the source for update details

"setvisitproperty" - run serverside SetVisitProperty

"getvisitproperty" - run serverside GetVisitProperty

Return

When the ajax call returns, it calls your handler (a callback) with the result set as it's argument. The format of the results depends on the responseFormat and ajaxMethod arguments and is described there.

Example

In your server-side code:

remoteQueryKey = cp.setRemoteQuery( "select top 1 name from ccMembers order by id desc" )

cj.ajax.getTable

cj.ajax.getTable(handler,queryKey,args,pageSize,pageNumber)

Arguments

handler - the javascript function (event handler) to be called when the ajax call returns. The response from the ajax call is passed to the handler as it's single argument. For example, if your handler is

function myHandler( resultSet ) {}

then the handler would be 'myHandler'

queryKey - a string that uniquely identifies the query record in the Remote Query content. If you need to run a query on a client-side event, you can create the query in the Remote Query content table and add a unique key to the record. To execute this query, include the key in the queryKey argument of this call. To programmatically create a query and get a key, see the Contensive webclient reference, GetAjaxQueryKey method.

args - A list of arguments to be passed to the server for processing with the query. They are in 'name=value&name=value' format. Each name and each value must be individually escaped before assembling the string. Depending on the QueryType setup for this key, the args can be used differently.

QueryType argument setup in the Remote Query content table:

SQLQuery - args are replacement name=value pairs

ContentInsert - args are fieldname=value pairs, but all fieldnames must be in the fieldnamelist

ContentUpdate - args are fieldname=value pairs, but all fieldnames must be in the fieldnamelist

pageSize - records to be returned

pageNumber - the page where the records begin

Return

.

Example

.

cj.ajax.getNameArray

cj.ajax.getNameArray(handler,queryKey,args,pageSize,pageNumber)

Arguments

handler - the javascript function (event handler) to be called when the ajax call returns. The response from the ajax call is passed to the handler as it's single argument. For example, if your handler is

function myHandler( resultSet ) {}

then the handler would be 'myHandler'

queryKey - a string that uniquely identifies the query record in the Remote Query content. If you need to run a query on a client-side event, you can create the query in the Remote Query content table and add a unique key to the record. To execute this query, include the key in the queryKey argument of this call. To programmatically create a query and get a key, see the Contensive webclient reference, GetAjaxQueryKey method.

args - A list of arguments to be passed to the server for processing with the query. They are in 'name=value&name=value' format. Each name and each value must be individually escaped before assembling the string. Depending on the QueryType setup for this key, the args can be used differently.

QueryType argument setup in the Remote Query content table:

SQLQuery - args are replacement name=value pairs

ContentInsert - args are fieldname=value pairs, but all fieldnames must be in the fieldnamelist

ContentUpdate - args are fieldname=value pairs, but all fieldnames must be in the fieldnamelist

pageSize - records to be returned

pageNumber - the page where the records begin

Return

.

Example

.

cj.ajax.getNameValue

cj.ajax.getNameValue(handler,queryKey,args)

Arguments

handler - the javascript function (event handler) to be called when the ajax call returns. The response from the ajax call is passed to the handler as it's single argument. For example, if your handler is

function myHandler( resultSet ) {}

then the handler would be 'myHandler'

queryKey - a string that uniquely identifies the query record in the Remote Query content. If you need to run a query on a client-side event, you can create the query in the Remote Query content table and add a unique key to the record. To execute this query, include the key in the queryKey argument of this call. To programmatically create a query and get a key, see the Contensive webclient reference, GetAjaxQueryKey method.

args - A list of arguments to be passed to the server for processing with the query. They are in 'name=value&name=value' format. Each name and each value must be individually escaped before assembling the string. Depending on the QueryType setup for this key, the args can be used differently.

QueryType argument setup in the Remote Query content table:

SQLQuery - args are replacement name=value pairs

ContentInsert - args are fieldname=value pairs, but all fieldnames must be in the fieldnamelist

ContentUpdate - args are fieldname=value pairs, but all fieldnames must be in the fieldnamelist

Return

.

Example

.

cj.ajax.update

cj.ajax.update(handler,queryKey,criteria,setPairs)

Arguments

handler - the javascript function (event handler) to be called when the ajax call returns. The response from the ajax call is passed to the handler as it's single argument. For example, if your handler is

function myHandler( resultSet ) {}

then the handler would be 'myHandler'

queryKey - a string that uniquely identifies the query record in the Remote Query content. If you need to run a query on a client-side event, you can create the query in the Remote Query content table and add a unique key to the record. To execute this query, include the key in the queryKey argument of this call. To programmatically create a query and get a key, see the Contensive webclient reference, GetAjaxQueryKey method.

criteria - .

setPairs - .

Return

.

Example

.

cj.ajax.setVisitProperty

cj.ajax.setVisitProperty(handler,propertyName,propertyValue)

Arguments

handler - the javascript function (event handler) to be called when the ajax call returns. The response from the ajax call is passed to the handler as it's single argument. For example, if your handler is

function myHandler( resultSet ) {}

then the handler would be 'myHandler'

propertyName - .

propertyValue - .

Return

.

Example

.

cj.ajax.getVisitProperty

cj.ajax.getVisitProperty(handler,propertyName,propertyValueDefault)

Arguments

handler - the javascript function (event handler) to be called when the ajax call returns. The response from the ajax call is passed to the handler as it's single argument. For example, if your handler is

Return

Example

cj.ajax.addon

Arguments

Return

Example

cj.ajax.addonCallback

cj.ajax.addonCallback(addonName,queryString,callback,callbackArg)

Arguments

addonName - the remoteMethod addon to call on the server.

queryString - the querystring to pass to the server addon.

callback - When the method returns, it will call this function with two possible arguments. The frist argument is always the serverResponse. If the callbackArg is included in this call, it will be the second argument in the callback.

callbackArg - When included, this argument is passed to the callback routine as its second argument.