4,251
社区成员
发帖
与我相关
我的任务
分享
$('span[class="colors"]').on('click', function() {
var colorID = $(this).attr('id');
// 给选择的颜色添加红边框以便提醒客户
// border:1px solid red;
$('span[id="'+colorID+'"]').css('border', '1px solid red')
.siblings().css('border', '0 none');
$.post('selectColors', { colorID: colorID }, function(result) {
alert(result);
}, 'json');
//$('#color').val(colorID); // hidden
});
/**
* 选择商品颜色以显示相应存货数量
*
*/
public function selectColors() {
// 通过AJAX返回相应颜色的商品存货数量
if ($this->isAjax()) {
$colorID = Input::getVar($_POST['colorID']); // color的colorID
$proID = Input::getVar($_GET['id']); // 当前商品 id
$count = M('ColorsCount')->where('proID = '.$proID.' and colorID = '.$colorID)->limit('1')->getField('count');
if ($count) {
$this->ajaxReturn($count, '', 1);
} else {
$this->ajaxReturn(0, '', 0);
}
}
}
用 post地址用 U()吧 U("Products/selectColors"); 这会生成一个连接地址
ajaxReturn 表示没用过
一般就直接 echo json_encode(array(
'count'=>1,
'state'=>1,
));
public function selectColors() {
// 通过AJAX返回相应颜色的商品存货数量
if ($this->isAjax()) {
OB_clean();
$colorID = Input::getVar($_POST['colorID']); // color的colorID
$proID = Input::getVar($_GET['id']); // 当前商品 id
$count = M('ColorsCount')->where('proID = '.$proID.' and colorID = '.$colorID)->limit('1')->getField('count');
if ($count) {
$this->ajaxReturn($count, '', 1);
} else {
$this->ajaxReturn(0, '', 0);
}
Die();
}
}