【问题标题】:How to serialize Arraylist form如何序列化 Arraylist 表单
【发布时间】:2014-12-05 10:54:06
【问题描述】:

我正在使用以下表单进行序列化和提交,但它没有提交给定的表单

HTML

<form action="" id="post_message_form">
    <textarea name="message" style="width:100%;height:80px" id="text_message" cssClass="form-control"></textarea>
    <input type="hidden" name="postImageseList[0].largePicPath" class="img-dtl" value="/img/post/large/0020603xpd4ps7ew_1_7gwy2kc44f141777.jpg" />
     <input type="hidden" name="postImageseList[1].largePicPath" class="img-dtl" value="/img/post/large/0020603xpd4ps7ew_1_7gwy2kc44f141666.jpg" />
    <button type="submit" id="submit_status_button">Submit</button>
</form>

jQuery

$("#post_message_form").on("submit", function (f) {
      f.preventDefault();
      console.log($("#post_message_form").serialize());
      alert($("#post_message_form").serialize());
      $.ajax({
          type: 'POST',
          url: 'PostMessage',
          data: $("#post_message_form").serialize(),
          dataType: "text html",
          success: function (data) {

          }
      }).fail(function (xhr, status, error) {
          alert("Error");
          alert('error status:' + status);
      });
  });

字段name="postImageseList[0].largePicPath" 是动态生成的字段,它可能是0 或更多。 如何序列化上面的表格。

我试过了here

【问题讨论】:

  • 似乎没问题。 “url:'PostMessage'”看起来很奇怪
  • 您需要在 ajax 调用中提供正确的 url。那么它应该可以正常工作。
  • PostMessage 有什么问题
  • @user3263194 以上代码是否正确
  • 你能解释一下什么是'PostMessage'吗?你是指这里的一些jsp页面吗?那么你需要添加 .jsp

标签: jquery forms jsp serialization


【解决方案1】:

为动态生成的字段添加名称属性。

尝试使用以下代码:

var formData = $('#form').serializeObject();
$.ajax({
      type: 'POST',
      url: 'http://www.smsiland.com/PostMessage',
      data: formData.serialize(),
      dataType: "text html",
      success: function (data) {

      }
  })
updated fiddle: 
http://jsfiddle.net/seb0k7np/4/

【讨论】:

  • 这里 var formData = $('#form').serializeObject();它显示Uncaught TypeError: undefined is not a function
猜你喜欢
  • 1970-01-01
  • 2014-04-12
  • 2015-06-28
  • 1970-01-01
  • 2011-09-05
  • 1970-01-01
  • 2011-03-26
  • 1970-01-01
  • 2011-07-08
相关资源
最近更新 更多