如何在存储到数据库时防止/停止编码textarea的值 [英] how to Prevent / stop encoding the value of textarea while storing to database

查看:76
本文介绍了如何在存储到数据库时防止/停止编码textarea的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文字区域。当我在其中输入html代码并保存数据时,它会自动编码并添加& lt; &安培; GT; &安培; NBSP;



我如何防止这种情况并将数据存储在数据库中而不进行编码。如果我访问相同的数据,我希望它在没有编码或解码的情况下显示或被检索。在emailTemplate中我得到了编码数据。

我的代码::

< pre lang =Javascript> function SaveEmailContentData(){

var emailTemplate = $( #textareaEmailHtmlContent)。val();
var emailCategoryID = parseInt ($( #ddlSelectCorpSearch)。val());
var corporateId = ClientID;
var TemplateId = 0 ;
if ' @ Model.TemplateID' != ' null'&& ' @ Model.TemplateID'!= ' 0'){

TemplateId = parseInt ' @ Model.TemplateID');

}

$ .ajax({
url:' ../../ Setup / Setup / SaveEmailContent'
dataType:' json'
类型:' POST'
data: JSON .stringify({EmailContent:emailTemplate,EmailContentID:emailCategoryID,ClientID:corporateId,TempID:TemplateId}),
cache: false
contentType:' application / json; charset = utf- 8'
成功: function (结果){
debugger ;
if (result == 成功){
showMessage( 更新成功 电子邮件内容已成功更新);
}
else {
showMessage( 更新失败 电子邮件内容无法更新 );
}
},
错误: function (){

alert( error);
}
});
}

解决方案

#textareaEmailHtmlContent)VAL();
var emailCategoryID = parseInt


(< span class =code-string> #ddlSelectCorpSearch)。val());
var corporateId = ClientID;
var TemplateId = 0 ;
if ' @ Model.TemplateID' != ' null'&& ' @ Model.TemplateID'!= ' 0'){

TemplateId = parseInt ' @ Model.TemplateID');

}


.ajax({
url:' ../../ Setup / Setup / SaveEmailContent'
dataType:' json'
类型:' POST'
data: JSON .stringify({EmailContent:emailTemplate,EmailContentID:emailCategoryID,ClientID:corporateId,TempID:TemplateId}),
cache: false
contentType:' application / json; charset = utf-8'
成功: function (结果){
debugger ;
if (result == 成功){
showMessage( 更新成功 电子邮件内容已成功更新);
}
else {
showMessage( 更新失败 电子邮件内容无法更新 );
}
},
错误: function (){

alert( error);
}
});
}


I have one text area. When I enter html code in it and save the data, it is encoding automatically and adding &lt; &gt; &nbsp; etc.

How can I prevent this and store my data in database without encoding. If I access same data, I would like it to display or be retreived without encoding or decoding.In emailTemplate i am getting that encoded data.
My code ::

function SaveEmailContentData() {

     var emailTemplate = $("#textareaEmailHtmlContent").val();        
     var emailCategoryID =parseInt($("#ddlSelectCorpSearch").val());
     var corporateId = ClientID;
     var TemplateId = 0;
     if ('@Model.TemplateID' != 'null' && '@Model.TemplateID' != '0') {

         TemplateId = parseInt('@Model.TemplateID');

     }

     $.ajax({
         url: '../../Setup/Setup/SaveEmailContent',
         dataType: 'json',
         type: 'POST',
         data: JSON.stringify({ EmailContent: emailTemplate,EmailContentID:emailCategoryID, ClientID: corporateId, TempID: TemplateId }),
         cache: false,
         contentType: 'application/json; charset=utf-8',
         success: function (result) {
             debugger;
             if (result == "success") {
                 showMessage("Update Successful", "Email Content Successfully Updated");
             }
             else {
                 showMessage("Update Failed", "Email Content could not be Updated");
             }
         },
         error: function () {

             alert("error");
         }
     });
 }

解决方案

("#textareaEmailHtmlContent").val(); var emailCategoryID =parseInt(


("#ddlSelectCorpSearch").val()); var corporateId = ClientID; var TemplateId = 0; if ('@Model.TemplateID' != 'null' && '@Model.TemplateID' != '0') { TemplateId = parseInt('@Model.TemplateID'); }


.ajax({ url: '../../Setup/Setup/SaveEmailContent', dataType: 'json', type: 'POST', data: JSON.stringify({ EmailContent: emailTemplate,EmailContentID:emailCategoryID, ClientID: corporateId, TempID: TemplateId }), cache: false, contentType: 'application/json; charset=utf-8', success: function (result) { debugger; if (result == "success") { showMessage("Update Successful", "Email Content Successfully Updated"); } else { showMessage("Update Failed", "Email Content could not be Updated"); } }, error: function () { alert("error"); } }); }


这篇关于如何在存储到数据库时防止/停止编码textarea的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆