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 中,我有以下简单代码:
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 组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何将 javascript 对象发送到远程 CFC 组件


基础教程推荐
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01