我正在使用 cfc 将 ASP.NET Web 服务数据转换为冷融合查询对象。我在我的 jquery 代码中使用 getJSON 调用返回该查询对象。但是,返回的数据被格式化为 wddx 数据包而不是 JSON 数据集,并且代码似乎没有完成。不知道我做错了什么。
$(document).ready(function(){
$("#submitForm").click(function(e){
e.preventDefault();
e.stopPropagation();
internetUsage();
});
});
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 ALERT NEVER FIRES
});
}
我可以确认它是从getInternetUsage () 函数(如下)返回的真正格式良好的查询对象。我不知道为什么它作为 WDDX 数据包通过。
<cffunction name="getInternetUsage" access="remote" returnType="any" returnformat="JSON" output="false">
<cfargument name="SessionID" required="true">
<cfargument name="CustomerCode" required="true">
<cfargument name="FullUserName" required="true">
<cfargument name="StartDate" required="true">
<cfargument name="EndDate" required="true">
<cfargument name="entity" required="false" default="Table">
<cfset var qResult = 0>
<cfset var strWS = invokeInternetUsage(
SessionID=arguments.SessionID,
CustomerCode=arguments.CustomerCode,
FullUserName=arguments.FullUserName,
StartDate=arguments.StartDate,
EndDate=arguments.EndDate)>
<cfset var aResult = convertDotNetDataset(strWS)>
<--- extract the queries from the returned struct --->
<cfif arguments.entity is 'Table'>
<cfset qResult = aResult.Table>
<cfelseif arguments.entity is 'Table1'>
<cfset qResult = aResult.Table1>
</cfif>
<cfreturn qResult>
</cffunction>
<cffunction name="invokeInternetUsage" access="remote" returnType="any" output="false">
<cfargument name="SessionID" required="true">
<cfargument name="CustomerCode" required="true">
<cfargument name="FullUserName" required="true">
<cfargument name="StartDate" required="true">
<cfargument name="EndDate" required="true">
<cfset var aTemp = "">
<cfinvoke
webservice="http://Portal/internet.asmx?WSDL"
method="Usage"
returnvariable="aTemp">
<cfinvokeargument name="SessionID" value="#arguments.SessionID#"/>
<cfinvokeargument name="CustomerCode" value="#arguments.CustomerCode#"/>
<cfinvokeargument name="FullUserName" value="#arguments.FullUserName#"/>
<cfinvokeargument name="StartDate" value="#arguments.StartDate#"/>
<cfinvokeargument name="EndDate" value="#arguments.EndDate#"/>
</cfinvoke>
<cfreturn aTemp>
</cffunction>
<!--- convertDotNetDataset --->
<!--- Converts a dotnet dataset into a structure of queries --->
<cffunction name="convertDotNetDataset" access="remote" returnType="any" output="false"
hint="takes a .Net dataset and converts it to a CF structure of queries">
<cfargument name="dataset" required="true">
<cfset var Local = StructNew()>
<cfset Local.result = structNew() />
<cfset Local.aDataset = arguments.dataset.get_any() />
<cfset Local.xSchema = xmlParse(Local.aDataset[1]) />
<cfset Local.xData = xmlParse(Local.aDataset[2]) />
<!--- Create Queries --->
<cfset Local.xTables = Local.xSchema["xs:schema"]["xs:element"]["xs:complexType"]["xs:choice"] />
<cfloop from="1" to="#arrayLen(Local.xTables.xmlChildren)#" index="Local.i">
<cfset Local.tableName = Local.xTables.xmlChildren[Local.i].xmlAttributes.name />
<cfset Local.xColumns = Local.xTables.xmlChildren[Local.i].xmlChildren[1].xmlChildren[1].xmlChildren/>
<cfset Local.result[Local.tableName] = queryNew("") />
<cfloop from="1" to="#arrayLen(Local.xColumns)#" index="Local.j">
<cfif left(Local.xColumns[Local.j].xmlAttributes.name,6) neq 'Column'>
<cfset queryAddColumn(Local.result[Local.tableName], Local.xColumns[Local.j].xmlAttributes.name, arrayNew(1)) />
</cfif>
</cfloop>
</cfloop>
<!--- see if there are any row of data, if not exit --->
<cfif NOT StructKeyExists(Local.xData["diffgr:diffgram"], "NewDataSet")>
<cfreturn Local.result>
</cfif>
<!--- Populate Queries --->
<cfset Local.xRows = Local.xData["diffgr:diffgram"]["NewDataSet"] />
<cfloop from="1" to="#arrayLen(Local.xRows.xmlChildren)#" index="Local.i">
<cfset Local.thisRow = Local.xRows.xmlChildren[Local.i] />
<cfset Local.tableName = Local.thisRow.xmlName />
<cfset queryAddRow(Local.result[Local.tableName], 1) />
<cfloop from="1" to="#arrayLen(Local.thisRow.xmlChildren)#" index="Local.j">
<cfif left(Local.thisRow.xmlChildren[Local.j].xmlName,6) neq 'Column'>
<cfset querySetCell(Local.result[Local.tableName], Local.thisRow.xmlChildren[Local.j].xmlName, Local.thisRow.xmlChildren[Local.j].xmlText, Local.result[Local.tableName].recordCount) />
</cfif>
</cfloop>
</cfloop>
<cfreturn Local.result>
</cffunction>
编辑-CFC
<cffunction name="invokeInternetUsage" access="remote" returnType="any" output="false">
<cfargument name="SessionID" required="true">
<cfargument name="CustomerCode" required="true">
<cfargument name="FullUserName" required="true">
<cfargument name="StartDate" required="true">
<cfargument name="EndDate" required="true">
<cfset var aTemp = "">
<cftry>
<cfinvoke
webservice="http://Portal/internet.asmx?WSDL"
method="Usage"
returnvariable="aTemp">
<cfinvokeargument name="SessionID" value="#arguments.SessionID#"/>
<cfinvokeargument name="CustomerCode" value="#arguments.CustomerCode#"/>
<cfinvokeargument name="FullUserName" value="#arguments.FullUserName#"/>
<cfinvokeargument name="StartDate" value="#arguments.StartDate#"/>
<cfinvokeargument name="EndDate" value="#arguments.EndDate#"/>
</cfinvoke>
<cfcatch></cfcatch>
</cftry>
<cfreturn aTemp>
</cffunction>
<!--- convertDotNetDataset --->
<cffunction name="convertDotNetDataset" access="remote" returnType="any" output="false"
hint="takes a .Net dataset and converts it to a CF structure of queries">
<cfargument name="dataset" required="true">
<cfset var Local = StructNew()>
<cfset Local.result = structNew() />
<cfset Local.aDataset = arguments.dataset.get_any() />
<cfset Local.xSchema = xmlParse(Local.aDataset[1]) />
<cfset Local.xData = xmlParse(Local.aDataset[2]) />
<!--- Create Queries --->
<cfset Local.xTables = Local.xSchema["xs:schema"]["xs:element"]["xs:complexType"]["xs:choice"] />
<cfloop from="1" to="#arrayLen(Local.xTables.xmlChildren)#" index="Local.i">
<cfset Local.tableName = Local.xTables.xmlChildren[Local.i].xmlAttributes.name />
<cfset Local.xColumns = Local.xTables.xmlChildren[Local.i].xmlChildren[1].xmlChildren[1].xmlChildren/>
<cfset Local.result[Local.tableName] = queryNew("") />
<cfloop from="1" to="#arrayLen(Local.xColumns)#" index="Local.j">
<cfif left(Local.xColumns[Local.j].xmlAttributes.name,6) neq 'Column'>
<cfset queryAddColumn(Local.result[Local.tableName], Local.xColumns[Local.j].xmlAttributes.name, arrayNew(1)) />
</cfif>
</cfloop>
</cfloop>
<!--- see if there are any row of data, if not exit --->
<cfif NOT StructKeyExists(Local.xData["diffgr:diffgram"], "NewDataSet")>
<cfreturn Local.result>
</cfif>
<!--- Populate Queries --->
<cfset Local.xRows = Local.xData["diffgr:diffgram"]["NewDataSet"] />
<cfloop from="1" to="#arrayLen(Local.xRows.xmlChildren)#" index="Local.i">
<cftry>
<cfset Local.thisRow = Local.xRows.xmlChildren[Local.i] />
<cfset Local.tableName = Local.thisRow.xmlName />
<cfset queryAddRow(Local.result[Local.tableName], 1) />
<cfloop from="1" to="#arrayLen(Local.thisRow.xmlChildren)#" index="Local.j">
<cfif left(Local.thisRow.xmlChildren[Local.j].xmlName,6) neq 'Column'>
<cfset querySetCell(Local.result[Local.tableName], Local.thisRow.xmlChildren[Local.j].xmlName, Local.thisRow.xmlChildren[Local.j].xmlText, Local.result[Local.tableName].recordCount) />
</cfif>
</cfloop>
<cfcatch></cfcatch>
</cftry>
</cfloop>
<cfreturn Local.result>