I'm sending some serialized data to a PHP script via AJAX:
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++ ) {
.....
}
}
I had the impression that one could loop through the $_POST['items']
var without any conversion, but I'm getting the serialized data instead:
item[]=val_1&item[]=val_2&item[]=val_3& ... &item[]=val_n
How can I loop through this?
Thanks in advance