【发布时间】:2012-02-17 23:01:07
【问题描述】:
我使用 jQuery UI 可排序插件,但未能成功使用 AJAX 发送“订单”变量(一个数组)。在 ajax 发送“订单”之后不再是一个数组。我想要一个只针对 ajax 发送的解决方案。
$("#list-cat").sortable({
placeholder: 'highlight',
update: function() {
var order = $('#list-cat').sortable('serialize');
$.ajax({
dataType: 'json',
type: "POST",
url: "my_url.php",
data: { action: "edit_cat_order", id_member: "<?php echo $id_member; ?>", id_page: "<?php echo $id_page; ?>", order: order },
success: function(data){
if (data.a == true){
$.colorbox({ html: data.b });
}
},
error:function (xhr, ajaxOptions, thrownError){
alert(xhr.responseText);
}
});
}
});
在“my_url.php”中,foreach 循环无法将 $_POST['order'] 识别为数组:“为 foreach() 提供的参数无效 ...”。我认为问题出在“数据”行,因为 $_POST['order'] 在我使用时是一个数组:
$.post("my_url.php", order);
【问题讨论】: