简体   繁体   English

无法使用form2js.js将表单数据转换为JSON对象

[英]Not able to convert form data into JSON object using form2js.js

I am using form2js.js for converting my form data into a JSON object. 我使用form2js.js将表单数据转换为JSON对象。

Here is the code: 这是代码:

var loginData = form2js('loginForm', '.', true);
console.log("FormData=" + JSON.stringify(loginData));

But the JSON String is empty. 但是JSON字符串是空的。 loginform is the ID of my form. loginform是我的表单的ID。 I have searched for help on but I am not getting anything. 我已经寻求帮助,但我没有得到任何东西。

Here is the HTML form: 这是HTML表单:

<form action="index.html" class="padder" id="loginForm" name="loginForm">                                
   <label class="control-label">User</label>
   <input id="userId" type="text" placeholder="User ID" class="form-control">                               
   <input type="password" id="password" placeholder="Passcode" class="form-control"> 
   <button type="submit" id="signInBtn" class="btn btn-info">Sign in</button>                               
</form>

The problem seems to be the missing name attribute 问题似乎是缺少name属性

<form action="index.html" class="padder" id="loginForm" name="loginForm">
    <label class="control-label">User</label>
    <input name="userId" id="userId" type="text" placeholder="User ID" class="form-control" />
    <input name="password" type="password" id="password" placeholder="Passcode" class="form-control" />
    <button type="submit" id="signInBtn" class="btn btn-info">Sign in</button>
</form>

Demo: Fiddle 演示: 小提琴

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

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