【发布时间】:2017-06-02 01:30:38
【问题描述】:
我正在通过 AJAX 向 PHP 脚本发送一些序列化数据:
HTML:
<table class="mytable">
<tbody>
<tr id="item_01">
<td>content</td>
</tr>
<tr id="item_02">
<td>content</td>
</tr>
<tr id="item_03">
<td>content</td>
</tr>
<tr id="item_04">
<td>content</td>
</tr>
<tr id="item_05">
<td>content</td>
</tr>
</tbody>
</table>
JS:
$( '.mytable tbody' ).sortable({
update: function() {
items = $( this ).sortable( 'serialize' );
$.ajax({
url: 'ajax.php',
type: 'post',
data: { action: 'foo', items }
cache: false,
error: function() {
console.log( 'Error' );
}
});
}
});
PHP:
$action = $_POST['action'];
if ($action == 'foo') {
$items = $_POST['items'];
for ( $i = 0; $i < count($items); $i++ ) {
.....
}
}
我的印象是可以循环遍历 $_POST['items'] var 而无需任何转换,但我得到的是序列化数据:
item[]=val_1&item[]=val_2&item[]=val_3& ... &item[]=val_n
我怎样才能遍历这个?
提前致谢
【问题讨论】:
标签: jquery ajax jquery-ui serialization jquery-ui-sortable