Coldfusion jQuery getJSON:获取WDDX而不是JSON

我使用Brian Rinaldi的coldfusion函数将dotnet webservice数据集转换为查询结构。 然后将每个查询作为JSON返回到客户端页面以在jQuery函数中使用。

查询是有效的查询对象。 但是,JSON没有被返回。 相反,我得到WDDX如下:

 
2010-01-30T00:00:00+13:00 2010-01-29T00:00:00+13:00

使用以下代码:

 function internetUsage(){ $.getJSON("system.cfc",{ method:'getInternetUsage', SessionID:$("#vSessionID").val(), CustomerCode:$("#vCustomerCode").val(), FullUserName:$("#selUser").val(), StartDate:$("#vStartDate").val(), EndDate:$("#vEndDate").val(), returnformat:'json', queryformat:'column' },function(res,code){ alert('hello'); // THIS NEVER FIRES! }); } 

所以,我尝试让CFC将查询转换为JSON并返回JSON-ified结果。 这有点好用,因为它返回了有效的JSON但它仍然包含在标签中,如下所示:

 
{ "recordcount": 31, "columnlist": "callcharge,callreference,connduration,conntype,description,dest_number,pages,settingcount,startdate,starttime,subscribercode,usage", "data": [ { "callcharge": "", "callreference": "", "connduration": 86403, "conntype": "UBS", "description": "dageorgetti", "dest_number": "", "pages": "", "settingcount": 5, "startdate": "2010-01-30T00:00:00+13:00", "starttime": "2010-01-30T00:00:00+13:00", "subscribercode": "dageorgetti", "usage": 33.7300 }...... ......

实现上述目标的要求如下:

 function internetUsage(){ $.getJSON("system.cfc",{ method:'getInternetUsage', SessionID:$("#vSessionID").val(), CustomerCode:$("#vCustomerCode").val(), FullUserName:$("#selUser").val(), StartDate:$("#vStartDate").val(), EndDate:$("#vEndDate").val(), jsonEncode:true // the cfc converts query to JSON },function(res,code){ alert('Hello'); // still not firing }); } 

我在CFC中使用returntype =“JSON”。 cfc非常复杂,我认为我不需要在这里粘贴它。 我可以确认它肯定是生成有效的查询对象,转换函数似乎成功转换为有效的JSON。 我不知道为什么它会回到包含在wddxPacket标签中的客户端。

编辑 – CFC

                                                            

您正在手工构建JSON,但cfc方法将该返回值视为要包装在WDDX数据包中的字符串。 您应该尝试将returnformat="plain"添加到cfc方法中。 此外,您正在使用.getJSON() 。 相反,使用.get()

快速浏览一下jQuery源代码,可以看出getJSON()只是get() ,其中JSON属性已经硬编码:

 getJSON: function( url, data, callback ) { return jQuery.get(url, data, callback, "json"); } 

每当我从CFC返回JSON数据时,我的函数往往如下所示:

    

尝试通过浏览器运行CFC。

我首先在CFC中尝试了并获得了WDDX。 然后我将其更改为plain并直接通过浏览器运行它但它返回了一个错误。 然后再次更改为JSON并使用浏览器进行检查。 它按预期返回JSON。