因业务需求  要讲如下编辑器中带有样式的数据传入数据库保存

第一种方法  json格式传入

   $(".privilegezn_page .btn_ok").click(function () {
if (editor.html() == "")
{
alert("优惠使用指南内容不能为空")
} else {
var str = HTMLEncode(editor.html());
console.log(str);
if (($("select")).length > 0) {
var hotelid = $("#hotel option:selected").attr("value");
} else {
var hotelid = $("#hotelid").val();
}
var cz = $("#xg").val();//操作名id
var gnbh = $("#gnbh").val();
var obj = new Object();
obj.text = str;
obj.xgid = hotelid;
 function HTMLEncode(text){
text = text.replace(/&/g, "&") ;
text = text.replace(/</g, "'<'") ;
text = text.replace(/>/g, "'>'") ;
return text;
}

                 obj.gnbh = gnbh;
obj.cz = cz;
console.log(JSON.stringify(obj));
$.ajax({
type: "POST",
url: "/Business/yhsyznxg",
data:{json:JSON.stringify(obj)},
success: function (data) {
var f = $.parseJSON(data);
if (f.yz1) {
alert("添加成功!");
if ($("#yhsyzncx").length > 0) {
$("#yhsyzncx").trigger("click");
} else {
location.replace(location.href);
}
}
else if (f.yz1 == false) {
alert("添加失败!");
location.replace(location.href);
}
if (f.yz2) {
alert("修改成功!");
if ($("#yhsyzncx").length > 0) {
$("#yhsyzncx").trigger("click");
} else {
location.replace(location.href);
}
}
else if (f.yz2 == false) {
alert("修改失败!");
location.replace(location.href);
}
}
});
}
})

后台页面:

  //优惠使用指南
[HttpPost]
public ActionResult yhsyznxg(string json)
{
JObject l = (JObject)JsonConvert.DeserializeObject(json);
//数据库为空则添加
int xgid = (int)l["xgid"];
int gnbh = (int)l["gnbh"];
int cz = (int)l["cz"];
string text = (string)l["text"];
string str = text.Replace("'<'", "<"); //解码去除 html中< >
string str1 = str.Replace("'>'", ">");
var cx = db.yhsyzn.FirstOrDefault(u => u.hotelid == xgid);
JObject array = new JObject();
if (cx != null) //修改
{
if (Session["yhid"] != null)
{
int id = (int)Session["yhid"]; bool pd = qxyz.czyz(id, gnbh, cz); //为什么还要查询一遍权限
if (pd)
{
yhsyzn a = db.yhsyzn.FirstOrDefault(u => u.hotelid == xgid);//查询到对应id
a.text = str1;
db.Entry(a).State = System.Data.Entity.EntityState.Modified; //什么更新???
db.SaveChanges();
array["yz2"] = true;
}
else
{
array["yz2"] = false;
}
}
else
{
array["yz2"] = false;
}
}
else //添加
{
if (Session["yhid"] != null)
{
int id = (int)Session["yhid"];
bool pd = qxyz.czyz(id, gnbh, cz); //为什么还要查询一遍权限
if (pd)
{
yhsyzn a = new yhsyzn();
a.hotelid = xgid;
a.text = text;
db.yhsyzn.Add(a);
db.SaveChanges();
array["yz1"] = true;
}
else
{
array["yz1"] = false;
}
}
}
return Content(array.ToString());
}

Ajax中参数带有html格式的 传入后台保存【一】的更多相关文章

  1. Ajax中参数带有html格式的 传入后台保存【二】

    KindEditor.ready(function (K) { //编辑器插件 window.editor1 = K.create('#ctjs', { uploadJson: '/Hotelgl/U ...

  2. Ajax中返回数据的格式

    Ajax中常见的返回数据的格式有三种:分别为文本,XML和JSON 返回的文本格式我们在上一堂课Ajax基础介绍中已经介绍过了 Ajax.php Form.html:通过Ajax对象的response ...

  3. Ajax中XML和JSON格式的优劣比较

    刚做完一个小的使用Ajax的项目.整个小项目使用JavaScript做客户端,使用PHP做服务器端.利用xmlHttpRequest组件作为交互工具,利用XML作为数据传输的格式.做完后基本做一个简单 ...

  4. ajax中url赋json格式的值时发生中文乱码的相关问题

    具体流程:转入到jsp界面时会加载ajax,ajax转到url时传带hide在jsp界面的值titleString,其来源见下面的代码. String title=new String("\ ...

  5. ajax中参数traditional的作用

    在使用ajax向后台传值的时候,有的时 $.ajax({ type: "post", async: true, data: { "records": [&quo ...

  6. SQL查询语句中参数带有中文查询不到结果

    今天写个小demo的时候发现sql语句里面的username为中文的时候就不能查到正确结果,sql语句如下: String sql = "select * from user where u ...

  7. SpringMVC中使用Ajax POST请求以json格式传递参数服务端通过request.getParameter("name")无法获取参数值问题分析

    SpringMVC中使用Ajax POST请求以json格式传递参数服务端通过request.getParameter("name")无法获取参数值问题分析 一:问题demo展示 ...

  8. JQuery中$.ajax()方法参数详解 及 async属性说明

    url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 ...

  9. 【转】Ajax中send方法参数的使用(get/post)

    Ajax中send方法参数的使用 一般情况下,使用Ajax提交的参数多是些简单的字符串,可以直接使用GET方法将要提交的参数写到open方法的url参数中,此时send方法的参数为null. 例如 : ...

随机推荐

  1. JavaScript字符和数组一些基本算法题

    1.翻转字符串 例子(要求:先把字符串转化成数组,再借助数组的reverse方法翻转数组顺序,最后把数组转化成字符串) function reverseString(str) { str=str.sp ...

  2. WHAT?【 $.fn.extend() 】vs【 $.extend() 】

    废话不多说,干货来了,转自http://www.cnblogs.com/hellman/p/4349777.html (function($){ $.fn.extend({ test:function ...

  3. 前端——HTML笔记Two

    web前端需要掌握:HTML.CSS.JavaScript语言.这三门技术用来实现: 1. HTML是网页内容的载体.内容就是网页制作者放在页面上想要让用户浏览的信息,可以包含文字.图片.视频等. 2 ...

  4. winServer2008添加IIS服务

    右键我的电脑,选择管理,打开服务器管理器 点击左边菜单栏角色调出角色窗口 接着点击添加角色,弹出添加角色向导 点击下一步进入服务器角色选项 勾选Web服务器(IIS),点击下一步 出现 点击下一步,出 ...

  5. django 学习笔记(一)搭建基础环境

    1.安装django 下载地址 https://github.com/django/django 解压后进入文件夹运行指令 >> python setup.py install 2.创建工 ...

  6. 原图旋转/缩放 然后画布画图 ImageProcessor

    //旋转 byte[] photoBytes = File.ReadAllBytes(HttpContext.Current.Server.MapPath(diyInfo.ImageUrl)); Im ...

  7. C#调用winhttp组件 POST登录迅雷

    下面是封装好的winhttp类 using System; using System.Collections.Generic; using System.Linq; using System.Text ...

  8. Chapter 21_5.2 tab扩展

    在Lua中,像这样()的空白捕获具有特殊意义.表示捕获它在目标字符串中的位置,返回一个数字: print(string.match("hello","()ll()&quo ...

  9. Jquery 操作DropDownList 根据条件选中

    $("#<%=DDLCounty.ClientID%> option").each(function () { if ($(this).text() == $(&quo ...

  10. brew install nvm

    brew install nvm mkdir ~/.nvm nano ~/.bash_profilectrl+x 退出 source ~/.bash_profile echo $NVM_DIR nvm ...