Return to Product Support > Learning Center > Developer References > Javascript API > cj.ajax

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:

  1. 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.
  2. 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

cj.ajax.data(handler,queryKey,args,pageSize,pageNumber,responseFormat,ajaxMethod)

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 format
    When 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" )

bind a hotspot to cj.ajax.data('showLastUser',(the string remoteQueryKey) ,'',1,1,'namevalue','data')

cp.doc.addHeadJavascript( "function showLastUser(results) {alert('Last user was '+results.name)}" );


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

function myHandler( resultSet ) {}

then the handler would be 'myHandler'

propertyName - .

propertyValueDefault - .

Return

.

Example

.

cj.ajax.url

cj.ajax.url(localUrl,formId,destinationId,onEmptyHideId,onEmptyShowId)

Arguments

localUrl

formId

destinationId

onEmptyHideId

onEmptyShowId

Return

.

Example

.

cj.ajax.addon

cj.ajax.addon(addonName,queryString,formId,destinationId,onEmptyHideId,onEmptyShowID)

Arguments

addonName

queryString

formId

destinationId

onEmptyHideId

onEmptyShowId

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.

Return

.

Example

functionButtonClick() {
    var varString = 'button=submit';
    cj.ajax.addonCallback( 'registrationFormHandlerAddon', varString, callbackHandler, '1' );
    return false;
}

function callbackHander( serverResponse, passthroughArgument ) {
    alert('The call passed the argument ['+passthroughArgument+'], and server returned '+serverResponse );
}



cj.ajax.qs

cj.ajax.qs(queryString,formId,destinationId,onEmptyHideId,onEmptyShowID))

Arguments

queryString

formId

destinationId

onEmptyHideId

onEmptyShowId

Return

.

Example

.