简体   繁体   English

如何以html格式序列化所有数据

[英]How to serialize all data in html form

I am doing routine form submission in html and for some reason this time it is not working at all. 我正在用html进行常规表单提交,由于某种原因,这一次它根本无法正常工作。

I have put together quick fiddle ( https://jsfiddle.net/qrfoanh2/ ) : 我整理了一些小提琴( 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> 

I would like to serialize form data, but for some reason i only get radio box information and never data from text input field with email. 我想序列化表单数据,但是由于某种原因,我只获得单选框信息,而没有从文本输入字段中获得带有电子邮件的数据。 Please help 请帮忙

Give your input[type="email"] tag a name attribute. 给您的input [type =“ email”]标签添加名称属性。 Form inputs are referenced by name in the request when the form is submitted. 提交表单时,表单输入将在请求中按名称引用。

          <input type="email" name="email" class="form-control" id="inputEmail3" placeholder="Email">

I updated the fiddle you have posted. 我更新了您发布的小提琴。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM