将表单范围传递给远程cfc

时间:2010-03-29 23:50:48

标签: jquery ajax coldfusion cfc

使用access =“remote”将表单范围传递给cfc的语法是什么? 我有:

<cfcomponent>
<cfset Variables.Datasource = "xxx">

<cffunction name="Save" access="remote">
    <cfset var local = {}>

    <!--- todo: try/catch --->  
    <cfif arguments.PersonID>
        <cfquery datasource="#Variables.Datasource#">
        UPDATE Person
        SET FirstName = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.FirstName#">
        ,LastName = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.LastName#">
        WHERE PersonID = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.PersonID#">
        </cfquery>
        <cfset local.result = arguments.PersonID>
    <cfelse>
        <cfquery name="local.qry" datasource="#Variables.Datasource#">
        INSERT INTO Person(FirstName,LastName) VALUES(
        <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.FirstName#">
        ,<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.LastName#">
        );
        SELECT PersonID FROM Person 
        WHERE PersonID=Scope_Identity()
        </cfquery>
        <cfset local.result = local.qry.PersonID>
    </cfif>
    <cfreturn local.result>
</cffunction>
</cfcomponent>

我需要传入form.PersonID,form.firstname,form.lastname。

2 个答案:

答案 0 :(得分:1)

您的远程函数可以接受struct参数或3个字符串参数(PersonID,firstname和lastname)。

请参阅文档

中的<CFARGUMENT>

答案 1 :(得分:1)

一个无关的事情。在cf9中,您已经有本地结构等待。更多相关信息http://forta.com/blog/index.cfm/2009/6/21/The-New-ColdFusion-LOCAL-Scope