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 组件


- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- 失败的 Canvas 360 jquery 插件 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- 400或500级别的HTTP响应 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01