我试图将我的表单值传递给一个javascript函数,它将它们传入我的CFC函数以插入到数据库中,但它不工作。 JS代码如下:将ColdFusion表单值传递给javascript和CFC,代码不工作
更新:删除“。”在警报前()和URL:
$(document).ready(function() {
$("#createReport").click(function(f) {
var getReportName = $("input#reportName").val();
var getReportPath = $("input#reportPath").val();
var getReportDesc = $("input#reportDescrip").val();
var getReportCategory = $("input#categoryBox").val();
$.ajax({
url: "components/reportController.cfc?method=createReport&returnformat=json",
dataType: "JSON",
data:{
reportName: getReportName,
reportPath: getReportPath,
reportDescrip: getReportDesc,
categoryBox: getReportCategory
},
success: function(){
alert("You successfully added a new report to the system") }
});
});
});
ColdFusion表单代码:(更新我的形式取出闪存型和CFlayout)
<cfform name="addReportForm" height="400" width="500" enctype="multipart/form-data"> <!--- Form Initialization --->
<p> Report Name </p>
<cfinput type="Text" name="reportName" size="20"maxlength="35" label="Report Name" <!--- Report Name Field --->
value="Report Name" required="yes" id="reportName">
<p> Report Path </p>
<cfinput type="Text" name="reportPath" size="20" maxlength="35" label="Report Path" <!--- Report Path Field --->
value="Report Path" required="yes" id="reportPath">
<!--- Report Category Dropdown box --->
<p> Category </p>
<cfselect name="category" label="Category" id="categoryBox" message="Select Category" <!--- DB populated drop down box for reports. Required field. --->
width="250" required="yes" tooltip="Select Category"> <!--- Values are static for testing. CFSELECT to be populated by query--->
<option value="Admin Tools">Admin Tools </option>
<option value="Reports">Reports</option>
<option value="Vendor Tools">Vendor Tools </option>
<option value="Company Links">Company Links</option>
<option value="Operations"> Operations</option>
</cfselect>
<p> Report Description </p>
<cftextarea name="reportDescrip" size="20" maxlength="200" label="Report Description"
value=" Enter Report Description" required="yes" id="reportDescrip" width="600" height="250">
</cftextarea>
<br />
<br />
<cfinput type="button" name="createReport" label="Add New Report" value="Add New Report" id="createReport"/>
</cfform>
罐有人告诉我,我可能会做错了,它不工作。
更新:我打开了IE控制台和脚本有一个SCRIPT1010:该行预期的标识符错误: **成功:函数(){
警报(“您已成功添加了一个新的报告。系统“)} **
更新:消除了CF flash表单和指定的HTML作为cfform中的表单类型。 AJAX调用仍然不起作用。
你在做什么错的是你正在使用'cflayout'和'cfform'。虽然他们似乎是一个很好的解决方案......但他们不是。所有的ColdFusion UI功能都实现得很差,使用过时的库,功能受到严重限制。坚持使用普通的HTML表单,并使用类似Bootstrap的布局。 –
我不同意马特的意见。我在那里看到它。最好的办法是打开浏览器的开发人员工具,查看控制台的JS错误,并在提交表单时观察网络流量。你也需要纠正你的“类别”目标代码。现在它正在寻找一个“类别”标签。 斯科特说:“你在做什么错了......”这并没有错,但我也没有建议,要么出于同样的原因。但是你需要在浏览器中检查你的源代码,以验证它如何改变事情,如果你使用它们。 –
当你故意使用过时的,实施不善的工具.....你做错了。:D –