我如何发送javascript对象到远程CFC组件 [英] How can I send javascript object to a remote CFC Component
本文介绍了我如何发送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我有以下简单的code:
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>
有人能POIT我的方向与数据播放一次是在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面:
And on the CF side:
<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/
这篇关于我如何发送javascript对象到远程CFC组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文