我有这个js脚本:
$("#sortable").sortable({
axis: 'y',
handle: '.fancybox',
update: function(e, ui) {
debugger;
order= $.map($(this).find('li'), function(el) {
return el.id;
});
$.ajax({
type: "POST",
url: "inc/ajax/sortable/update.php",
data: { 'order':order },
success: function (msg) {
alert(msg);
},
error: function (xhr, err) {
alert("readyState: " + xhr.readyState + "\nstatus: " + xhr.status);
alert("responseText: " + xhr.responseText);
}
});
}
});
和 2 个 php 文件
在这里,我设置了 order 变量的值:
session_start();
unset($_SESSION['order']);
unset($_SESSION['ordine']);
unset($_SESSION['ordine']);
foreach($_POST['order'] as $val) {
print_r($_SESSION['order'][]=$val);
}
在这里我需要更新:
if(isset($_SESSION['order'])) {
print_r($_SESSION['order']);
foreach($_SESSION['img'] as $key=>$val) {
echo $_SESSION['order'][$key]." pentru ".$val."\n";
$sql="UPDATE `anunturi_images` SET `sort`=:i WHERE `id_imag`=:val" ;
$stmt = $this->dbh->prepare($sql);
$data = array(':i'=>$_SESSION['order'][$key],':val'=>$val);
$stmt->execute($data);
}
}
问题是:
当我排序两次时,订单变量的值就可以了,但如果我只排序一个,订单变量就是初始订单。
当我只排序一次时,如何正确设置 order 变量。