Mic*_* BW 4 ajax coldfusion jquery json cfc
我创建了一个javascript对象
var spanglist = {
one: q1,
two:q2,
three:q3,
four: q4};
Run Code Online (Sandbox Code Playgroud)
我创建了一个ajax jquery对象来将数据发送到CFC:
$.ajax({
url: 'gridly/components/pay.cfc',
type:"POST",
dataType:' json',
data: {method: "structFromJSobjt",
returnFormat:"json",
jsStruct: spanglist}
});
Run Code Online (Sandbox Code Playgroud)
在我的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>
Run Code Online (Sandbox Code Playgroud)
一旦有人在数据中,有人可以指导我使用数据.
就个人而言,我只会做一些细微的改动.例如:
$.ajax({
url: 'gridly/components/pay.cfc',
type:"POST",
dataType:' json',
data: {method: "structFromJSobjt",
returnFormat:"json",
jsStruct: JSON.stringify(spanglist)}
});
Run Code Online (Sandbox Code Playgroud)
在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>
Run Code Online (Sandbox Code Playgroud)
有一点需要注意的是,在某些浏览器中,JSON.stringify()方法的可用性很大.所以我建议从http://www.json.org/获取json2.js
归档时间: |
|
查看次数: |
1341 次 |
最近记录: |