NutzCN Logo
问答 $('form').serialize()问题
发布于 64天前 作者 蛋蛋的忧伤 98 次浏览 复制 上一个帖子 下一个帖子
标签:

我的form表单有若干字段,然后调用serialize这个方法后只给我一个键值对,很疑惑....
html代码:

<div class="row">
						<div class="col-xs-12">
							<!-- PAGE CONTENT BEGINS -->
							<form class="form-horizontal" id="form" role="form" method="post" action="${base}/general/agent/save">
								<div class="form-group">
									<label class="col-sm-3 control-label no-padding-right">编号</label>
									<div class="col-sm-9">
										<input type="text" name="sys_id" placeholder="编号" class="col-sm-5 form-input form-control required" disabled="disabled" value="${obj.sys_id!}"/>
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-3 control-label no-padding-right">账号</label>
									<div class="col-sm-9">
										<input type="text" name="phone" placeholder="账号" class="col-sm-5 form-input required" disabled="disabled" value="${obj.phone!}"/>
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-3 control-label no-padding-right">姓名</label>
									<div class="col-sm-9">
										<input type="text" name="username" placeholder="姓名" class="col-sm-5 form-input required" disabled="disabled" value="${obj.username!}"/>
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-3 control-label no-padding-right">费率</label>
									<div class="col-sm-9">
										<input type="text" name="rate" placeholder="费率" class="col-sm-5 form-input required" disabled="disabled" value="${obj.rate!}"/>
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-3 control-label no-padding-right">指定通道</label>
									<div class="col-sm-4">
										<select id="channel" class="col-sm-5 form-input form-select form-control" name="channel"   url="${base}/channel/select" n="name" v="code">
										</select>
									</div>
								</div>
								<div class="clearfix form-actions">
									<div class="col-md-offset-3 col-md-9">
										<button class="btn btn-white btn-info " onclick="sendForm('${base}/general/agent/save','form')" type="button">
											<i class="ace-icon fa fa-check bigger-110"></i>
											提交
										</button>
										&nbsp; &nbsp; &nbsp;
										<button class="btn btn-white" type="reset">
											<i class="ace-icon fa fa-undo bigger-110"></i>
											重置
										</button>
									</div>
								</div>
							</form>
						</div>
					</div>

js:

function sendForm(url,id){
    //console.log($('#'+id));
    console.log($('#'+id).serialize());
    $.ajax({
        url : url,
        type: "get",
        data:$('#'+id).serialize(),
        error: function(request) {
            alert("网络错误");
        },
        dataType:"json",
        success: function(data) {
            //alert(data);
            console.log(data);
            if (data.code ==1) {
                alert("操作成功!");
                location.reload();
            } else {
                alert(data.msg)
            }
        }
    });

}

我输出了一下,内容为

channel=ldz-api

很奇怪为什么只有一个,其他的都没解析出来....是我写错了吗...

4 回复
id="form"

能不能用心起名字,自己给自己挖坑

名字改了还是不行....我直接在form标签下加了个input,然后可以生成.....

disabled="disabled"

添加回复
请先登陆
回到顶部