JS代码如下:
/**
* 异步无刷新传值
*
* @param
* @arrange (编程之家) jb51.cc
**/
//修改商品
//把返回值放入表单中做默认值
function do_editgoods(id){
$('#editgoods').modal('open');
$.get('/Home/Price/edit/item_id/'+id,function(result){
document.getElementById(hid).value = result.content['id'];
document.getElementById(item_id).value = result.content['item_id'];
document.getElementById(outer_item_id).value = result.content['outer_item_id'];
document.getElementById(goods_name).value = result.content['goods_name'];
document.getElementById(standard).value = result.content['standard'];
document.getElementById(low_price).value = result.content['low_price'];
document.getElementById(minus_price).value = result.content['minus_price'];
document.getElementById(moni_url).value = result.content['moni_url'];
},'json');
return false;
}
//将表单的默认值通过异步传到控制器
function do_edit(){
$.post(
'/Home/Price/to_edit', { 'hid':$(.edit_hid).val(), 'item_id':$(.edit_item_id).val(), 'outer_item_id':$(.edit_outer_item_id).val(), 'goods_name':$(.edit_goods_name).val(), 'standard':$(.edit_standard).val(), 'low_price':$(.edit_low_price).val(), 'minus_price':$(.edit_minus_price).val(), 'moni_url':$(.edit_moni_url).val()
},function(result){
if(result.code == 200){
//$(#msg1).cl
$(#msg2).addClass('am-text-success');
$(#msg2).html('修改成功!');
$(#msg2).html(result.msg);
//window.location.href=/Home/Index/index.html;
}else{
//$(#msg1).addClass('am-text-danger');
$(#msg2).html(result.msg);
} },'json');
}
//控制器进行处理
/**
* 修改商品价格*/
public function edit(){
$map['item_id'] = $_GET['item_id']; //获取页面传过来的商品编号
$to_display = M('haoyao_price_compare') -> where($map) -> find(); //查处所需要的信息//成功后返回客户端新增的用户ID,并返回提示信息和操作状态
$this->ajaxReturn(array('code'=>200,'content'=>$to_display));//将获取到的数据返回到页面
}
public function to_edit(){
$map['id'] = $_POST['hid'];
//获取页面传过来的商品编号
$data['item_id'] = $_POST['item_id'];
//获取页面传过来的商品编号
$data['outer_item_id'] = $_POST['outer_item_id'];
//获取页面传过来的外部商家编号
$data['goods_name'] = $_POST['goods_name'];
//获取页面传过来的商品名称
$data['standard'] = $_POST['standard'];
//获取页面传过来的商品规格
$data['low_price'] = $_POST['low_price'];
//获取页面传过来的商品最低价格
$data['modi_time'] = date('Y-m-d H:i:s',time());
//获取页面传过来的商品修改时间
$data['minus_price'] = $_POST['minus_price'];
//获取页面传过来的商品优惠价格
$data['mino_url'] = $_POST['moni_url'];
//获取页面传过来的商品链接
$res = M('haoyao_price_compare')->where($map)->save($data);if($res){$this->ajaxReturn(array('code'=>200));
}
}
// 来自:编程之家 jb51.cc(jb51.cc)