Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_Related Related Topics sp_TopicIcon
Parse json data into coldfusion code
30/01/2013
16:10
Avatar
gena_mak
Member
Members
Forum Posts: 5
Member Since:
27/09/2012
sp_UserOfflineSmall Offline

Hi

I am working on generating a report with data in JSON format. Here is the action file that receives parameters and displays either html table with data or excel. I need help with parsing JSON data I am getting into required format (html or excel). I know how to work with excel formatting, I just need help with parsing JSON data and outputing it. I someone help me to complete the code, the part where it is passed from jquery to coldfusion. Any help is greatly appreciated.

Thank you

<cfajaxproxy cfc="components.acct.accttrx"> <script src="../jQuery/js/jquery-1.7.2.min.js"></script> <cfparam name="prD" default="0_0"> <cfparam name="sM" default="1"> <cfparam name="sY" default="2013"> <cfparam name="status" default="0"> <cfparam name="FORM.fileformat" default="html"> <script type="text/javascript"> jQuery(document).ready(function(){ var myURL = '../components/acct/accttrx.cfc'; function populateReport(){ $.ajax({ url: myURL + "?method=GetTranactions", type: 'POST', data: { prID: '<cfoutput>#prD#</cfoutput>', mn: '<cfoutput>#sM#</cfoutput>', yr: '<cfoutput>#sY#</cfoutput>', st: '<cfoutput>#status#</cfoutput>', ea_adm:'1', slist:'', lang: '1' }, dataType: "json", success: function(data){ $.each(data, function(index, item) { //(item.description,item.balance,item.accttrx_status); // I need help from this point to pass // data to cfml part of my code }); }, error: function(){ alert("An error has occurred while fetching records"); } }); populateReport(); }); </script> </HEAD> <body> <cfif FORM.fileformat Eq 'excel'> <cfset VARIABLES.vcFilename = "thisreport_" & DateFormat(Now(), "yyyymmdd") & "-" & TimeFormat(Now(), "HHmmss") & ".xls"> <cfsetting enablecfoutputonly="Yes"> <cfcontent type="application/vnd.ms-excel"> <cfheader name="Content-Disposition" value="inline;filename=""#VARIABLES.vcFilename#"""> <cfoutput> <!--- here display data from JSON object ---> </cfoutput> <cfsetting enablecfoutputonly="No"> <cfelse> <div id="reportcontents" /> <!--- display row html ---> </cfif>



Below is the Response:

{"ROWS":[
  {
   "balance":-642.04000,
   "description":"ABC Company",
   "ee_name":"Jon, Doe",
   "plan_id":0,
   "debit":25000.22000,
   "accttrx_year":2013,
   "sponsor_id":5,
   "division_id":0,
   "accttrx_month":1,
   "credit":26591.25000,
   "trx_employee_id":1,
   "cheque_amt":25000.00000,
   "cheque_no":"",
   "accttrx_status":"B",
   "accttrx_id":15
  },
  {
   "balance":-642.04000,
   "description":"ABC Company",
   "ee_name":"James, Done",
   "plan_id":0,
   "debit":32233.07000,
   "accttrx_year":2013,
   "sponsor_id":5,
   "division_id":0,
   "accttrx_month":1,
   "credit":30000.00000,
   "trx_employee_id":1,
   "cheque_amt":32233.07000,
   "cheque_no":"",
   "accttrx_status":"P",
   "accttrx_id":14
  }
  ],
  "PAGE":1,
  "RECORDS":2,
  "TOTAL":1.0
}
Forum Timezone: Europe/Sofia

Most Users Ever Online: 496

Currently Online:
31 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

OlegK: 1255

markw65: 179

kobruleht: 144

phicarre: 132

YamilBracho: 124

Renso: 118

Member Stats:

Guest Posters: 447

Members: 11373

Moderators: 2

Admins: 1

Forum Stats:

Groups: 1

Forums: 8

Topics: 10592

Posts: 31289

Newest Members:

, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information