【发布时间】:2012-10-13 10:53:44
【问题描述】:
我有一个表单,其中包含几个输入文本字段和一个可排序的列表(下面的代码)。下面的函数检索保存到数组(订单)中的新位置。但是,我想要将数组包含在表单中,这样当用户完成排序、填写文本字段并提交表单时,该数组将成为表单的一部分。
那么,我怎样才能用 AJAX 把这个数组放到表单中呢?
$('#listElements').sortable({
//revert: true,
update: function(event, ui) {
var order = [];
$('.listObject li').each(function (e) {
order.push($(this).attr('id'));
});
$.ajax({
url: "/index.php?type=list&action=showList&listId=1",
type: "post",
data: {
order_data: order
}
}).success(function (data) {
console.log(data);
});
}
});
注意:为了清楚起见,我想将数组放入表单中。
【问题讨论】:
-
您想将数组(从订单)放入表单,或者您想将其放入 index.php 中?
-
http://stackoverflow.com/questions/4239460/serializing-an-array-in-jquery可能重复
标签: php jquery ajax arrays forms