我正在努力使用codeigniter创建它的方式。我正在打开一个编辑页面(订单)。我想更改页面上的数据,这些数据将在离开字段后动态保存。但是,当我没有成功地使用codeigniter的方式或者以“好的方式”使用其他词语时。我不想依赖于uri结构并使用uri段获取数据,就像现在的代码一样。我想改进下面的代码,但我没有成功......
这是打开我的视图的代码
public function edit($id = NULL) {
// Fetch a page or set a new one
$this->load->model('shop_m');
$this->load->model('details_m');
$this->data['subtitle'] = 'incoming';
if ($id) {
if($this->transfer_m->get_permission($id) > 0){
$this->data['transfer'] = $this->transfer_m->get_rec($id);
// $this->data['transfer'] = $this->transfer_m->get($id,true);
count($this->data['transfer']) || $this->data['errors'][] = 'page could not be found';
$this->data['details'] = $this->details_m->get_by(array('doc_no' => $id),FALSE);
}
else{
redirect('admin/Dashboard', 'refresh');
}
} else {
$this->data['transfer'] = $this->transfer_m->get_new();
}
$this->data['shop_from'] = $this->shop_m->get($this->data['transfer']->from_customer,TRUE);
$this->data['shop_to'] = $this->shop_m->get($this->data['transfer']->to_customer,TRUE);
// Load the view
$this->data['subview'] = 'pages/details/transfer_edit';
$this->load->view('pages/main', $this->data);
}
我的ajax电话
function add_shop(shop){
var id = $('#doc_no').text();
$.ajax({
url: base_url+"/admin/transfer/add_shop/"+id+"/"+shop,
async: false,
type: "POST",
data: "",
dataType: "html",
success: function(data) {
$('#ajax-content-container').hide();
}
})
}
我的控制器功能添加商店
public function add_shop($id){
$data = array('to_customer' => $this->uri->segment(5));
$this->transfer_m->save($data,$id);
}
任何帮助将不胜感激!!
答案 0 :(得分:2)
您可以使用帖子。修改您的ajax调用并传递如下数据。请参阅此处的文档https://api.jquery.com/jquery.post/
data: { id: id, shop: shop }
可以访问此数据$this->input->post('id'); $this->input->post('shop');