gpt4 book ai didi

jQuery/ColdFusion Ajax 创建 session 变量

转载 作者:行者123 更新时间:2023-12-01 04:43:49 24 4
gpt4 key购买 nike

我正在尝试使用 ColdFusion 和 JQuery 创建单页应用程序。我试图有一个(打印标签)按钮,当单击它时,它将打开一个引导模式,询问一个问题“请输入标签起始编号:”这个文本框我想以某种方式创建一个可以在(dealerlabels.pdf) pdf,点击 Bootstrap Modal 的 Accept 后打开。在 console.log(data) 中,我得到正确的响应,显示输入到 $("#LabelNum") 中的数字,但我无法创建 session 变量。当我执行 cfdump 时,结构中不存在任何内容。有人可以告诉我我做错了什么吗?

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>

DealerLabels.cfm 上的 CFDUMP enter image description here

最佳答案

我建议你简单地做你想做的事,创建一个 session 变量。在index_proxy.cfm中你有这个:

<cfset labelNum = form.LabelNum >

除此之外或代替此,请执行以下操作:

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

关于jQuery/ColdFusion Ajax 创建 session 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32993488/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com