zoukankan      html  css  js  c++  java
  • Ajax序列化表单为Json字符串POST到后台

    $.fn.serializeObject = function () {
                    var o = {};
                    var a = this.serializeArray();
                    $.each(a, function () {
                        if (o[this.name] !== undefined) {
                            if (!o[this.name].push) {
                                o[this.name] = [o[this.name]];
                            }
                            o[this.name].push(this.value || '');
                        } else {
                            o[this.name] = this.value || '';
                        }
                    });
                    return o;
                };
    
    $('input.pass').mouseup(function () {
                    alert(JSON.stringify($(this).parent().parent().serializeObject()) + '
    ' + typeof (JSON.stringify($(this).parent().parent().serializeObject())));
    
                    $.post('@Url.Action("CheckPartial", "Agent")', JSON.stringify($(this).parent().parent().serializeObject()))
                        .done(function (data) {
                            $(this).parents('div.custom-card').load(data);
                        })
                });




    [HttpPost]
    public ActionResult CheckPartial()//直接加参数获取不到POST过来的数据
    {
    Session["Id"] = 1;
    var UserID = Convert.ToInt32(Session["Id"]);

    
    

    using (var streamReader = new StreamReader(Request.InputStream))
    {
    var checkObject = JsonConvert.DeserializeObject<CheckPartial>(streamReader.ReadToEnd());

    
    

    using (HoldenZhongbaoEntities _context = new HoldenZhongbaoEntities())
    {
    //var checkObject = JsonConvert.DeserializeObject(checkJson);
    var checkOrderID = checkObject.OrderID as string;

    
    

    var order = _context
    .Cashes
    .Where(u => u.OrderID == checkOrderID)
    .FirstOrDefault();

    
    

    order.IsAdminCheck = checkObject.IsAdminCheck;
    order.AdminCheckTime = DateTime.Now;
    order.Note = checkObject.Note as string;

    
    

    _context.SaveChanges();

    
    

    return PartialView("CheckPartial", order);
    }
    }
    }

     

    这里

    .done(function (data) {
                            $(this).parents('div.custom-card').load(data);
    用的不对,load的参数是要发送GET请求时顺带的,局部刷新看下一篇
  • 相关阅读:
    MiniUi绑定mini-combobox下拉框
    ORA-01658:无法为表空间XXX中的段创建initial区
    ora-01033:oracle initialization or shutdown in progress 解决方法
    MVC示例
    NHibernate概念
    流程的python PDF高清版
    正则指引 pdf 高清版
    第三方库:logger,自定义日志封装模块
    python2.* 版本 与 3.* 版本中的区别
    Selenium2+python自动化-文件上传
  • 原文地址:https://www.cnblogs.com/Jayesslee/p/9244755.html
Copyright © 2011-2022 走看看