[英]Submit form from jQuery modal to a ColdFusion action page
我试图在我的ColdFusion应用程序中将一个非常简单的表单提交到一个操作页面,以更新一些数据库记录。
当我提交表格时,Firebug告诉我
500(元素NOTETEXT在FORM中未定义。)
这是我的JavaScript
<!---Javascript that submits the link notes changes --->
<script>
$(function(){
$("#noteForm").submit(function(){
// prevent native form submission here
$.ajax({
type: "POST",
data: $('#noteForm').serialize(),
dataType: 'json',
url: "actionpages/link_notes_action.cfm?id=2",
success: function(responseSubmit) {
alert("Success");
}
});
return false;
});
});
</script>
这是我的表格
<form id="noteForm">
<textarea id="noteText" name="noteText" cols="45" rows="10">#notes#</textarea><br />
<input name="submit" id="submitForm" type="submit" value="Update">
<input type="hidden" name="hidden" value="#get_dashboard_links.ID#">
</form>
这是我的行动页面:
<cfquery name="update" datasource="#datasource#">
update dashboard_links
set notes = '#form.noteText#'
where ID = #form.hidden#
</cfquery>
ColdFusion键取决于表单对象的名称,而不是ID。
将您的textarea更改为
<cftextarea id="noteText" name="noteText" cols="45" rows="10">
要么
这样就改变你的行动页面:
set notes = '#form.notes#'
(顺便说一句,我希望你实际上没有使用那个未经过滤的输入来更新你的数据库。你正在使用cfqueryparam
,对吧?)
当您提交表单时,请查看开发人员工具(在Chrome中)或FireBug(在Firefox中),我打赌您实际上并未将任何数据传递到您的“操作页面”。 当您在窗体上调用serialize()
时,实际上并没有将它传递给页面。
尝试将以下内容添加到$.ajax()
调用中:
data: JSON.stringify( data ),
此外,如果您要返回JSON,请使用此选项
dataType: 'json',
这将告诉jQuery自动将结果作为JSON处理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.