2015-10-07 2 views
2

Я пытаюсь создать одностраничное приложение с использованием ColdFusion и JQuery. Я пытаюсь иметь кнопку (Print Labels), которая при нажатии на нее откроет мода загрузочного мода, задав вопрос «Пожалуйста, введите начальный номер метки:» Это текстовое поле Я хочу каким-то образом создать переменную сеанса, которая может быть использована на (dealerlabels.pdf) pdf, который открывается При попадании Accept Bootstrap Modal. В console.log (data) я получаю правильный ответ, показывающий число, которое было введено в $ («# LabelNum»), но я не могу создать переменную сеанса. Когда я делаю cfdump, в структуре ничего не существует. Кто-нибудь скажет мне, что я делаю неправильно?jQuery/ColdFusion Ajax Создание переменной сеанса

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 на DealerLabels.cfm enter image description here

+0

насчет вашего Application.cfc - Вы настроили управление сеансами? – wiesion

+0

Куда вы делаете вы сбрасываете? Теги 'cfheader' и' cfcontent' не позволят вам увидеть что-нибудь полезное. –

+0

Из кода, который вы поделили, не похоже, что вы возвращаете что-либо из 'index_proxy.cfm'. Это нормально, но я бы ожидал, что 'console.log (data)' в вашей функции успеха будет пустым. ** РЕДАКТИРОВАТЬ ** Ничего, я вижу здесь 'cfoutput'. –

ответ

1

Я полагаю, что вы просто делать то, что вы говорите, что вы хотите сделать, создать переменную сеанса. В index_proxy.cfm у вас есть это:

<cfset labelNum = form.LabelNum > 

В дополнение или вместо этого, сделайте следующее:

<cfset session.dealerwork.labels.labelNum = form.LabelNum > 
+0

Хорошо, что было легко. Интересно, почему этот код '' не работал? –

Смежные вопросы