我正在用html进行常规表单提交,由于某种原因,这一次它根本无法正常工作。
我整理了一些小提琴(https://jsfiddle.net/qrfoanh2/):
$(document).ready(function () {
$('#formy').on('submit', function(e) {
e.preventDefault();
var data = $('#formy').serialize();
$(".miejsce").html(data);
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form id="formy">
<div class="form-group row">
<label for="inputEmail3" class="col-sm-2 col-form-label">Email</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="inputEmail3" placeholder="Email">
</div>
</div>
<div class="row">
<legend class="col-form-label col-sm-2 pt-0">Radios</legend>
<div class="col-sm-10">
<div class="form-check">
<input class="form-check-input" type="radio" name="gridRadios" id="gridRadios1" value="option1" checked>
<label class="form-check-label" for="gridRadios1">Reset zegara odblokowania dni</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="gridRadios" id="gridRadios2" value="option2">
<label class="form-check-label" for="gridRadios2">Edycja dni subskrypcji</label>
</div>
</div>
</div>
<div class="form-group row">
<div class="col-sm-10">
<button type="submit" class="btn btn-primary" onclick="action();"> - GO : GO - </button>
</div>
</div>
</form>
<div class="miejsce" style="background:#ddd;width:100%;height:200px;"></div>
我想序列化表单数据,但是由于某种原因,我只获得单选框信息,而从未从带有电子邮件的文本输入字段中获得数据。请帮助
答案 0 :(得分:3)
给您的输入[type =“ email”]标签一个 name 属性。提交表单时,表单输入将在请求中按名称引用。
<input type="email" name="email" class="form-control" id="inputEmail3" placeholder="Email">
我更新了您发布的小提琴。