简体   繁体   English

ColdFusion处理AJAX JSON数据

[英]ColdFusion handling AJAX JSON data

I am setting up a local API as an additional step in my external API call using AJAX. 我正在使用AJAX在我的外部API调用中设置本地API作为附加步骤。 The sequence goes like this: 该序列如下所示:

  • Ajax call passes data to localAPI.cfm. Ajax调用将数据传递到localAPI.cfm。
  • Inside localAPI.cfm I have <cfhttp> to send the data to an external api. 在localAPI.cfm内部,我有<cfhttp> cfhttp <cfhttp>可以将数据发送到外部api。

However, after I pass the data to localAPI.cfm via ajax how do I target(grab) the data? 但是,在我通过ajax将数据传递到localAPI.cfm ,如何定位(抓取)数据?

Here is the ajax call 这是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) {}
   });

inside localAPI.cfm : 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. 我知道我丢失了一些东西,一旦我弄清楚如何获取通过AJAX传递的数据,就将其放置在cfhttpparam值中。

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"

You may want to look into getHttpRequestData() . 您可能需要研究getHttpRequestData() From there, you would use deserializeJSON() to get to the data sent to the cfm by the AJAX call. 从那里,您将使用deserializeJSON()来获取通过AJAX调用发送到cfm的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM