2

I am trying to create a Single Page Application using ColdFusion and JQuery. I am trying to have a (Print Labels) button that when it is clicked it will open up a bootstrap modal asking a question "Please enter label start number:" This textbox I want to somehow create a session variable that may be used on the (dealerlabels.pdf) pdf that opens Upon hit of Accept of the Bootstrap Modal. In the console.log(data) I am getting the correct response showing the number that was entered into $("#LabelNum") but I am unable to create the session variable. When I do a cfdump nothing exists in the struct. Will someone please tell me what I am doing wrong?

http://jsfiddle.net/1zka4soy/13/

JS

$(document).ready(function () { // What happens when a user hits the "Accept" button on the dealer form $(".label_accept").click(function () { $('#LabelMaker').modal('hide'); }); $('#labelForm').on('submit', function (e) { e.preventDefault(); alert($(this).serialize()); $.ajax({ // the location of the CFC to run url: "index_proxy.cfm", // send a GET HTTP operation type: "post", // tell jQuery we're getting JSON back dataType: "json", // send the data to the CFC data: $('#labelForm').serialize(), // this gets the data returned on success success: function (data) { console.log(data); if (data !== "") { var link = "DealerLabels.cfm"; window.open(link,'newStuff'); } }, // this runs if an error error: function (xhr, textStatus, errorThrown) { // show error console.log(errorThrown); } }); }); }); 

index_proxy.cfm

<cfset labelNum = form.LabelNum > <cfoutput> #labelNum# </Cfoutput> <!---Initial check to see if we have a core structure to store our data.---> <cfif not structKeyExists(session, "dealerwork")> <cfset session.dealerwork = {}> </cfif> <!--- initial defaults for the first section ---> <cfif not structKeyExists(session.checkout, "labels")> <cfset session.dealerwork.labels= {LabelNum=""}> </cfif> <!---form fields will default according to session values---> <cfparam name="#labelNum#" default="#session.dealerwork.labels.LabelNum#"> <cfset errors = []> <cfif not arrayLen(errors)> <cfset session.dealerwork.labels = {LabelNum=form.LabelNum}> </cfif> 

DealerLabels.cfm

<cfset LabelNum = #session.dealerwork.labels.LabelNum#> <cfset tempFilePath = "/mytemppath.pdf"> <cfpdfform source="forms/DealerLabel.pdf" action="populate" destination="#tempFilePath#"> <cfpdfformparam name="One" value="#LabelNum#"> </cfpdfform> <cfheader name="Content-Disposition" value="attachment;filename=LabelMaker.pdf"> <cfcontent type="application/pdf" file="#tempFilePath#" deleteFile="true"> 

Application.cfc

<cfcomponent> <cfset this.datasource = "DealerTracking" > <cfset this.name = "DealerTracking"> <cfset this.sessionManagement = "true"> <cfset this.sessionTimeout = "#createTimeSpan(0,5,0,0)#"> <cfset this.clientManagement = "false"> <cfset this.loginStorage = "session"> <cfset this.setDomainCookies = "true"> <cfset this.scriptProtect = "true"> <cfset this.applicationTimeout = "#createTimeSpan(0,5,0,0)#"> <cffunction name="onError" returntype="void"> <cfargument name="Exception" required="true" > <cfargument name="EventName" required="true" type="string" > <cfif arguments.EventName eq "true"> <cflog text="Error occurred: #arguments.exception#: #arguments.EventName#" type="error" file="#this.name#" > <cfelse> <cflog text="Error occurred: #arguments.exception#" type="error" file="#this.name#" > </cfif> </cffunction> <cffunction name="onApplicationStart" returntype="boolean"> <cfset application.activeSessions = 0> <cflog text="The Dealer Tracking application has started." type="information" file="#this.name#" > <cfreturn true> </cffunction> <cffunction name="onApplicationEnd" returntype="void"> <cfargument name="appScope" required = "true" > <cflog text="The Dealer Tracking application shut down." type="information" file="#this.name#" > </cffunction> </cfcomponent> 

CFDUMP on DealerLabels.cfm enter image description here

6
  • What about your Application.cfc - did you set up session management? Commented Oct 7, 2015 at 13:29
  • Where are you doing you dump? The cfheader and cfcontent tags will prevent you from seeing anything useful. Commented Oct 7, 2015 at 13:55
  • From the code you shared it doesn't look like you are returning anything from index_proxy.cfm. That is okay but I would expect the console.log(data) in your success function to be empty. EDIT Never mind I see a cfoutput in there now. Commented Oct 7, 2015 at 13:56
  • disregard my previous comment, I see that you are indeed outputting the number which gets returned from the AJAX call. What do you get when you cfdump the session in DealerLabels.cfm? Add a cfabort after the cfdump to stop any further processing so you can see the dump. Commented Oct 7, 2015 at 14:23
  • So you don't see the session.dealerwork.labels structure in your session dump? Commented Oct 7, 2015 at 15:38

1 Answer 1

1

I suggest that you simply do what you say you want to do, create a session variable. In index_proxy.cfm you have this:

<cfset labelNum = form.LabelNum > 

In addition to or instead of that, do this:

<cfset session.dealerwork.labels.labelNum = form.LabelNum > 
Sign up to request clarification or add additional context in comments.

1 Comment

Well that was easy. I wonder why this code <cfset session.dealerwork.labels = {LabelNum=form.LabelNum}> did not work?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.