【发布时间】:2016-11-12 00:48:08
【问题描述】:
我有几个表单字段,我正在通过 ajax 调用更新数据库。 数据库已成功更新,但如果将 DoubleQuotes 提交到数据库,我无法正确更新表单。
假设按下 Enter 时 Some "Quotes" are needed 已作为子任务提交。
DB 会看到Some "Quotes" are needed。
但是如果使用encodeURI(data.TASKDESCRIPTION) 并且页面会在文本框的焦点外看到Some%20%22Quotes%22%20are%20needed。
如果页面刷新页面显示Some "Quotes" are needed成功。
<cfif isDefined("action") and action is "editSubtask">
<cfquery name="udpateSubTask" datasource="#siteDataSource#">
UPDATE ProjectTaskSubtasks
SET taskDescription = <cfqueryparam value="#form.TASKDESCRIPTION#" cfsqltype="cf_sql_varchar" >
WHERE guid = <cfqueryparam value="#form.SUBTASKGUID#" cfsqltype="cf_sql_varchar" >
</cfquery>
<cfquery name="selectSubTask" datasource="#siteDataSource#">
SELECT guid as SUBTASKGUID, taskDescription
FROM ProjectTaskSubtasks
WHERE guid = <cfqueryparam value="#form.SUBTASKGUID#" cfsqltype="cf_sql_varchar" >
LIMIT 1
</cfquery>
<cfoutput>#serializeJSON(selectSubTask, "struct")#</cfoutput>
<cfabort>
</cfif>
<!--- ----------------------------------------- --->
<cfloop query="#subtasks#">
<div id="_#subtasks.guid#" class="col-xs-12">
<input type="text" id="description-#subtasks.guid#" name="description-#subtasks.guid#" class="#subtasks.isComplete is 0 ? '' : 'strike'# subtask-hide col-xs-10" value="#EncodeForHTMLAttribute(subtasks.taskDescription)#" onClick="allowInput(this)"/>
<!--- #EncodeForHTMLAttribute(subtasks.taskDescription)# Works Great for the starting Value of this TextBox from DB especially if doublequotes in subtasks.taskDescription DB Field --->
</div>
<!--- ----------------------------------------- --->
<script>
var taskDescription_#subtasks.guid# = "#encodeForJavaScript(subtasks.taskDescription)#"; //this appears to work as needed
$('##description-#subtasks.guid#').keyup(function(e){
var code = e.which;
if(code===13){
$.post(
'#cgi.SCRIPT_NAME#',
{
action: 'editSubtask',
SUBTASKGUID: $(this).parent()[0].id.replace('_',''),
TASKDESCRIPTION: $(this).val()
},
function(data){
data = JSON.parse(data);
data = data[0];
taskDescription_#subtasks.guid# = encodeURI(data.TASKDESCRIPTION); //THIS DOES NOT WORK if doublequotes where submitted to the DB : when data comes back from editSubTask I need a way to update my Variable so on focus out it updates the field with the new information submitted .
$('##formButt').focus();
}
);
}
});
$('##description-#subtasks.guid#').focusout(function(){
/* .val(taskDescription_#subtasks.guid#)works great HERE on FocusOut doesn't change the Value from original var taskDescription_#subtasks.guid# = "#encodeForJavaScript(subtasks.taskDescription)#" */
$('##description-#subtasks.guid#').val(taskDescription_#subtasks.guid#).removeClass('subtask').addClass('subtask-hide');
setTimeout(function(){
$('##delete-#subtasks.guid#').removeClass('subtask-cancel').addClass('subtask-cancel-hide');
},150)
});
</script>
</cfloop>
【问题讨论】:
-
不理解上下文@Dan。是的,它成功进入了 rhe 数据库,我只需要在它从 Ajax 调用返回后再次在页面上正确显示它。特别是如果发送到数据库的内容中有双引号。
标签: javascript coldfusion