form表单序列化转换JSON

转载  Mr_ZhangAdd   2020-07-03   50人阅读  0 条评论
$.fn.serializeForJSON = 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;
        };
 
 
  $.ajax({
            type: "post",
            url: "*******",
            data: JSON.stringify($("#jxForm").serializeForJSON()),//$("#jxForm").serializeArray(),
            dataType: 'json',
            contentType: "application/json",
            success: function (rst) {
                console.log(rst);
                if (rst.code == 0) {
                    layer.msg(rst.msg, {time: 1000}, function () {
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                        parent.searchData();
                    });
                } else {
                    layer.msg(rst.msg, {time: 1000}, function () {
                    });
                }
            }
        });


本文地址:https://www.zjh336.cn/?id=1889
温馨提示:文章内容系作者个人观点,不代表华仔部落对观点赞同或支持。
版权声明:本文为转载文章,来源于 Mr_ZhangAdd ,版权归原作者所有,欢迎分享本文,转载请保留出处!

发表评论


表情

还没有留言,还不快点抢沙发?