ColdSpring will make your life much, much easier in the long run...

Here's how I handle JSON requests from jQuery, for instance. Your
mileage may differ:

ColdSpring creates a dataobject which is injected into a service. (I
do everything with stored procedures, so I just create a "dataobject",
and not "DAO" and/or "Gateway"). I then created a simple proxy object
that accesses the service layer from anywhere within my application:

<cfcomponent output="false" hint="Used by jQuery Ajax getJSON function
calls" displayname="proxy Service">
  <cfsetting showdebugoutput="no" enablecfoutputonly="yes"/>
  <cfcontent reset="yes" />
  <!---ColdSpring--->
  <cfset variables.sf = application.serviceFactory />
  <!--- general-purpose proxy function...will pass through any method
and arguments thrown at it to the underlying service --->

  <cffunction name="proxy" access="remote" returntype="any"
output="false">
    <cfargument name="service" type="string" required="yes"/>
    <cfargument name="remotemethod" type="string" required="yes"/>
    <cfset var svc = variables.sf.getBean(arguments.service) />
    <cfset var outvar = 0 />
    <cfinvoke component="#svc#" method="#arguments.remoteMethod#"
argumentcollection="#arguments#" returnvariable="outVar" />
    <cfif isDefined('outVar')>
        <cfreturn outVar />
    </cfif>
  </cffunction>
</cfcomponent>


I can then call any method from jQuery:

$.getJSON('model/services/proxyService.cfc', {
            method: "proxy",
            service: "someService",
            remotemethod: "someMethod",
            var1: $("#fieldA").val(),
            var2: $("#fieldB").val(),
            returnformat: "json"
        }, function(data){

     ....do something with the data....

     }
});

-- 
You received this message because you are subscribed to Mach-II for CFML list.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/mach-ii-for-coldfusion?hl=en

SVN: http://svn.mach-ii.com/machii/
Wiki / Documentation / Tickets: http://trac.mach-ii.com/machii/

Reply via email to