ajax代码:
$(".shelf").click(function() {
// 给每个输出结果加上其对应的num作为标记,以此作为ajax中的id值
var id = $(this).attr('num');
var obj = $(this);
// alert(id);
$.post('__CONTROLLER__/shelf', {
'id': id
}, function(data) {
if (data == 1) {
obj.parent().parent().hide();
}
});
});

以下是php代码:

// 下架商品
public function shelf($id){//链接数据库
$product=D('Product');
$row=$product->find($id);
$data['shelf']=abs($row['shelf']-1);
$data['time']=time();

$data['id']=I('post.id');
// echo "<pre>";
// print_r($row['shelf']);
// print_r($data['shelf']);
// echo "</pre>";
// exit;
// 根据条件更新记录
if ($product->save($data)) {
echo 1;
}else{
echo 2;
}
}



ajax快速实现商品上下架,很简单吧?