Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如何将javascript对象发送到远程CFC组件_Jquery_Ajax_Json_Coldfusion_Cfc - Fatal编程技术网

Jquery 如何将javascript对象发送到远程CFC组件

Jquery 如何将javascript对象发送到远程CFC组件,jquery,ajax,json,coldfusion,cfc,Jquery,Ajax,Json,Coldfusion,Cfc,我已经创建了一个javascript对象 var spanglist = { one: q1, two:q2, three:q3, four: q4}; 我创建ajax jquery对象以将数据发送到CFC: $.ajax({ url: 'gridly/components/pay.cfc', type:"POST", da

我已经创建了一个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>


一旦数据进入CFF功能,是否有人能告诉我使用数据的方向。

就我个人而言,我只会做一些细微的更改。例如:

$.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.js,非常感谢您的帮助。这似乎是一件很自然的事情,这样我就可以在将参数发送到服务器之前在客户端更好地验证参数。再一次,谢谢。