jQuery serialize()在ajax加载的表单上不起作用

时间:2013-06-02 10:30:25

标签: jquery twitter-bootstrap

我在ajax加载表单上遇到了serialize()的一些问题。

jQuery代码:

$(document).on("submit", this.id, function(e) {
  e.preventDefault();
  var frm     = e.target.id;
  var frmData = $("#"+frm).serialize();
  console.log(frm);
  console.log(frmData);
});

控制台输出:

  1. 登录表单
  2. (空文)
  3. 表单本身(bootstrap):

    <div class="tab-pane active" id="logintab">
      <div class="well">
        <form class="form-horizontal" id="loginForm">
          <div class="control-group">
            <label class="control-label" for="inputEmail">E-mail adres</label>
            <div class="controls">
              <input type="email" id="inputEmail" value="info@domainname.com" placeholder="E-mail adres" data-validation-email-message="Not a valid e-mail address"  required>
            </div>
          </div>
          <div class="control-group">
            <label class="control-label" for="inputPassword">Password</label>
            <div class="controls">
              <input type="password" id="inputPassword" value="test" placeholder="Wachtwoord" data-validation-required-message="Not a valid password"  required>
            </div>
          </div>
          <div class="control-group">
            <div class="controls">
              <button type="submit" class="btn submitbtn"><i class="icon-signin"></i> Inloggen</button>
            </div>
          </div>
        </form>
      </div>
    </div>
    

1 个答案:

答案 0 :(得分:8)

表单元素需要具有要序列化的名称和值,您的元素没有名称。如果添加名称:

<input type="email" name="email" id="inputEmail" ......

它运作得很好:

FIDDLE