ColdFusion处理AJAX JSON数据(ColdFusion handling AJAX JSON data)

我正在使用AJAX在我的外部API调用中设置本地API作为额外步骤。 顺序如下:

Ajax调用将数据传递给localAPI.cfm。 在localAPI.cfm中,我有<cfhttp> cfhttp <cfhttp>将数据发送到外部api。

但是,在我通过ajax将数据传递给localAPI.cfm ,如何定位(获取)数据?

这是ajax调用

$.ajax({ type: "POST", url: "MODULES/PAGES/API/localAPI.cfm", // The key needs to match your method's input parameter (case-sensitive). data: JSON.stringify(SDdata), contentType: "application/json; charset=utf-8", dataType: "json", success: function(data) {} });

在localAPI.cfm :

<cfhttp url = "http://<cfoutput>#PageAPILocation#</cfoutput>" method = "POST" result="result"> <cfhttpparam type="body" value="##"/> </cfhttp> <cftry> <cfset ReturnedData = deserializeJSON(result.FileContent)> <cfcatch> <cfdump var="#result#" /> </cfcatch> </cftry>

我知道我错过了一些东西,一旦我弄清楚如何抓取通过AJAX传递的数据,我会把它放在cfhttpparam值中。

这是什么通过:

{FunctionName: "PlanList", APIkey: "12345", PageNumber: "1", MaxRows: "10", ReturnType: "json"} APIkey:"12345" FunctionName:"PlanList" MaxRows:"10" PageNumber:"1" ReturnType:"json"

I am setting up a local API as an additional step in my external API call using AJAX. The sequence goes like this:

Ajax call passes data to localAPI.cfm. Inside localAPI.cfm I have <cfhttp> to send the data to an external api.

However, after I pass the data to localAPI.cfm via ajax how do I target(grab) the data?

Here is the ajax call

$.ajax({ type: "POST", url: "MODULES/PAGES/API/localAPI.cfm", // The key needs to match your method's input parameter (case-sensitive). data: JSON.stringify(SDdata), contentType: "application/json; charset=utf-8", dataType: "json", success: function(data) {} });

inside localAPI.cfm:

<cfhttp url = "http://<cfoutput>#PageAPILocation#</cfoutput>" method = "POST" result="result"> <cfhttpparam type="body" value="##"/> </cfhttp> <cftry> <cfset ReturnedData = deserializeJSON(result.FileContent)> <cfcatch> <cfdump var="#result#" /> </cfcatch> </cftry>

I know I'm missing something, once I can figure out how to grab the data being passed via AJAX I will place it in the cfhttpparam value.

Here is whats being passed:

{FunctionName: "PlanList", APIkey: "12345", PageNumber: "1", MaxRows: "10", ReturnType: "json"} APIkey:"12345" FunctionName:"PlanList" MaxRows:"10" PageNumber:"1" ReturnType:"json"

最满意答案

您可能想要查看getHttpRequestData() 。 从那里,您将使用deserializeJSON()来获取通过AJAX调用发送到cfm的数据。

You may want to look into getHttpRequestData(). From there, you would use deserializeJSON() to get to the data sent to the cfm by the AJAX call.

更多推荐

data,localAPI,cfm,AJAX,电脑培训,计算机培训,IT培训"/> <meta name="descri