如何将 javascript 对象发送到远程 CFC 组件 [英] How can I send javascript object to a remote CFC Component

查看:15
本文介绍了如何将 javascript 对象发送到远程 CFC 组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个 javascript 对象

I have created a javascript object

var spanglist = {
    one: q1,
    two:q2,
    three:q3,
    four: q4};

我创建了 ajax jquery 对象来将数据发送到 CFC:

I create the ajax jquery object to send the data to the CFC:

$.ajax({            
           url: 'gridly/components/pay.cfc',            
           type:"POST",            
            dataType:' json',            
            data: {method: "structFromJSobjt",            
                   returnFormat:"json",            
                   jsStruct: spanglist}
    });

在我的 cfc 中,我有以下简单代码:

in my cfc I have the following simple code:

<cffunction name="structFromJSobj" access="remote" output="false" >
    <cfargument name="jsStruct" required="true" default=""  />
    <!--- AT this point I would like to work with the data contained in the jsStruct object.  I can't access the data regardless of the typeI make the cfargument --->      
</cffunction>

一旦数据在 cffunction 中,有人可以指出我使用数据的方向吗?

Can someone poit me in the direction to play with the data once it is in the cffunction.

推荐答案

就个人而言,我只会做一些细微的改变.例如:

Personally, I would make only slight changes. For example:

$.ajax({            
           url: 'gridly/components/pay.cfc',            
           type:"POST",            
            dataType:' json',            
            data: {method: "structFromJSobjt",            
                   returnFormat:"json",            
                   jsStruct: JSON.stringify(spanglist)}
    });

在 CF 方面:

<cffunction name="structFromJSobj" access="remote" output="false" >
    <cfargument name="jsStruct" required="true" type="string"  />
    <cfset var cfStruct = DeserializeJSON(arguments.jsStruct)>

    <!--- now use your structure --->
</cffunction>

需要注意的一点是 JSON.stringify() 方法在某些浏览器中的可用性参差不齐.所以我建议从 http://www.json.org/

The one thing to note about this is the spotty availability of the JSON.stringify() method in some browsers. So I recommend getting json2.js from http://www.json.org/

这篇关于如何将 javascript 对象发送到远程 CFC 组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆