CFC Bind

Bind a single element in the page.

**************************************************************
tag
**************************************************************
<cfcfajaxproxy bind="cfc:railoAjax.tests.cfajaxproxy.files.test.getName({myForm:myName})"
onSuccess="updateDiv1" onError="onError"/>
**************************************************************
cfc
**************************************************************
<cffunction name="getName" access="remote" returntype="string">
<cfargument name="myName" type="string" required="true"/>
<cfreturn 'My Name is ' & arguments.myName/>
</cffunction>
**************************************************************
js
**************************************************************
updateDiv1 = function(data, textStatus){
document.getElementById('myDiv1').innerHTML = data;
}

Bind multiple element on the page.

The ajax call is made onChange of both the binded element and will send both elements values to cfc.

Element are included in a form with ID myForm2

Cfc return a string

**************************************************************
tag
**************************************************************
<cfajaxproxy bind="cfc:railoAjax.tests.cfajaxproxy.files.test.getInfo({myForm2:myName},{myForm2:myAge})"
onSuccess="updateDiv2" onError="onError"/>
**************************************************************
cfc
**************************************************************
<cffunction name="getInfo" access="remote" returntype="string">
<cfargument name="myName" type="string" required="true"/>
<cfargument name="myAge" type="numeric" required="true"/>
<cfreturn 'My Name is ' & arguments.myName & ' and I am ' & arguments.myAge & ' years old.'/>
</cffunction>
**************************************************************
js
**************************************************************
updateDiv2 = function(data, textStatus){
document.getElementById('myDiv2').innerHTML = data;
}

Change Default Event

{element@mousedown}

In this example also the element with name 'send' will trigger the binding on 'mouseover'

**************************************************************
tag
**************************************************************
<cfajaxproxy
bind="cfc:railoAjax.tests.cfajaxproxy.files.test.getInfo({myForm3:myName},{myForm3:myAge},{send@mousedown})"
onSuccess="updateDiv3" onError="onError"/>
**************************************************************
cfc
**************************************************************
same as previous
**************************************************************
js
**************************************************************
same as previous



------------------------------------------------------------------------------------------------

{element@none}

Same as before but in this case the element with '@none' will not react to any event. Binding is delegated to the 'mousedown' event on send2 element.

**************************************************************
tag
**************************************************************
<cfajaxproxy
bind="cfc:railoAjax.tests.cfajaxproxy.files.getInfo({myForm4:myName@none},{myForm4:myAge@none},{send@mousedown})"
onSuccess="updateDiv4" onError="onError"/>
**************************************************************
cfc
**************************************************************
same as previous
**************************************************************
js
**************************************************************
same as previous



Argument alias : (arg={myForm2:myName})

The value of the element with name 'city' will be passed as 'myCity'

In this case cfc return a json string that is evaluated by Railo.Ajax and pushed into listener as a js object.

**************************************************************
tag
**************************************************************
<cfajaxproxy
bind="cfc:railoAjax.tests.cfajaxproxy.files.getInfoJson({myForm5:myName},{myForm5:myAge},myCity={myForm5:city})"
onSuccess="updateDiv5" onError="onError"/>
**************************************************************
cfc
**************************************************************
<cffunction name="getInfoJson" access="remote" returntype="struct">
<cfargument name="myName" type="string" required="false"/>
<cfargument name="myAge" type="numeric" required="false" default="20"/>
<cfargument name="myCity" type="string" required="false" default=""/>
<cfscript>
var str = structnew();
str['myName'] = arguments.myName;
str['myAge'] = arguments.myAge;
str['myCity'] = arguments.myCity;
return str;
</cfscript>
</cffunction>
**************************************************************
Js Function
**************************************************************
var str = 'My name is ' + data['myName'] + '. I am ' + data['myAge'] +
' years old and I live in ' + data['myCity'];
document.getElementById('myDiv5').innerHTML = str;