The agnostic nature of cfajaxproxy.
I always thought that cfajaxproxy was inexorably tied to the Ajax functions built into ColdFusion.. I recently found out that
I was wrong.
CFAjaxproxy is used to create a javascript proxy of a ColdFusion Component (cfc) for use in the web client. This means any javascript,
not just ColdFusion based AJAX components.
Lets take the AJAX post code from my last post and see how it would work with cfajaxproxy.
This is the original code: It's calling action pages to execute ColdFusion components.
$("#getTOByWeek").live("click", function(){
$.ajax({
type:"post",
url:"webapps/hr/admin/actions/act_adminHR_Handler.cfm",
data:$("#toByWeek").serialize(),
cache:"false",
success: function(){
$("#content-box").load("webapps/hr/admin/display/dsp_TOList.cfm");
},
error: function(){
alert("data");
}
});
return false;
});
If I use cfajaxproxy it would look something like this, to achieve the same functionality
<cfajaxproxy cfc = "CFC name" jsclassname = "JavaScript proxy class name">
The CFC property instantiates the entire component, using dot notation (com.foo.bar.component), jsclassname is the name that is given to the function
inside javascript:
<cfajaxproxy cfc="hr.cfc.hr_dao" jsclassname="hr_dao">
This gives me a javascript representation of my hr_dao.cfc that can be used in any javascript case. //capture the click event
//instantiate the ColdFusion Function
<cfajaxproxy cfc="hr.cfc.hr_dao" jsclassname="hr_dao">
<script>
$("#getTOByWeek").click(function(objEvent){
//call the ColdFusion method directly
hr_dao.getTimeOffStatus(objEvent);
//trigger the success function based on return
return false;
});
<script>
No comments found.
Post a comment (login required)