jQuery/ColdFusion Ajax创建会话变量
我正在尝试使用ColdFusion和JQuery创建一个单页应用程序。我试图有一个(打印标签)按钮,当它被点击时,它将打开一个引导模式,询问一个问题“请输入标签开始编号:”这个文本框我想以某种方式创建一个会话变量,可以在(dealerlabels.pdf)pdf上使用,该pdf在点击接受引导模式时打开。在console.log(data)中,我得到了正确的响应,显示了在$(“#LabelNum”)中输入的数字,但我无法创建会话变量。当我执行cfdump时,结构中不存在任何内容。有人能告诉我我做错了什么吗 JSjQuery/ColdFusion Ajax创建会话变量,jquery,coldfusion,Jquery,Coldfusion,我正在尝试使用ColdFusion和JQuery创建一个单页应用程序。我试图有一个(打印标签)按钮,当它被点击时,它将打开一个引导模式,询问一个问题“请输入标签开始编号:”这个文本框我想以某种方式创建一个会话变量,可以在(dealerlabels.pdf)pdf上使用,该pdf在点击接受引导模式时打开。在console.log(data)中,我得到了正确的响应,显示了在$(“#LabelNum”)中输入的数字,但我无法创建会话变量。当我执行cfdump时,结构中不存在任何内容。有人能告诉我我做错
$(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\u 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>
<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">
#labelNum#
DealerLabels.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>
<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">
应用程序.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
我建议您只需按照自己的意愿去做,创建一个会话变量。在index_proxy.cfm中,您有以下内容:
<cfset labelNum = form.LabelNum >
除此之外,请执行以下操作:
<cfset session.dealerwork.labels.labelNum = form.LabelNum >
你的Application.cfc怎么样-你设置了会话管理吗?你在哪里转储?cfheader
和cfcontent
标记将阻止您查看任何有用的内容。从您共享的代码来看,您似乎没有从index\u proxy.cfm
返回任何内容。这没关系,但我希望success函数中的console.log(data)
为空。编辑别介意我现在在那里看到一个cfoutput
。忽略我之前的评论,我看到您确实在输出从AJAX调用返回的数字。在DealerLabels.cfm中cfdump会话时会得到什么?在cfdump之后添加cfabort以停止任何进一步的处理,这样您就可以看到转储。这样您就不会在会话转储中看到session.dealerwork.labels
结构了?这很简单。我想知道为什么这个代码不起作用?