2014-12-05 63 views
0

我使用以下格式进行序列化和提交,但不提交表单给出如何序列化ArrayList的形式

的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

+0

似乎是确定。 “url:'PostMessage'”看起来很奇怪 – Ferret 2014-12-05 11:02:15

+0

你需要在ajax调用中给出正确的url。那么它应该工作得很好。 – user3263194 2014-12-05 11:04:05

+0

PostMessage有什么问题 – xrcwrn 2014-12-05 11:04:46

回答

0

添加name属性动态生成的领域。

尝试使用下面的代码:

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/ 
+0

这里var formData = $('#form')。serializeObject();它显示'Uncaught TypeError:undefined不是函数' – xrcwrn 2014-12-08 05:07:06