我正在使用以下表单来序列化并提交,但它没有按照给出的
提交表单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 :(得分:0)
为动态生成的字段添加名称属性。
尝试使用以下代码:
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/