我创建了一个 javascript 对象
var spanglist = {
one: q1,
two:q2,
three:q3,
four: q4};
我创建 ajax jquery 对象以将数据发送到 CFC:
$.ajax({
url: 'gridly/components/pay.cfc',
type:"POST",
dataType:' json',
data: {method: "structFromJSobjt",
returnFormat:"json",
jsStruct: spanglist}
});
在我的 cfc 中,我有以下简单代码:
<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 中处理数据的方向吗?
就我个人而言,我只会做一些微小的改变。例如:
$.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() 方法在某些浏览器中的可用性不稳定。所以我建议从以下位置获取 json2.jshttp://www.json.org/ http://www.json.org/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)