0
我有幾個表單字段,我通過ajax調用來更新數據庫。 數據庫成功更新,但如果DoubleQuotes提交給數據庫,我無法正確更新表單。ColdFusion JavaScript等效於#encodeForJavaScript()#
說Some "Quotes" are needed
作爲按Enter時的子任務提交。
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。是的,它成功地進入了數據庫,我只需要在它從Ajax調用返回後再次正確地在頁面上顯示它。特別是如果發送到數據庫的內容有雙引號。 – shaun