【问题标题】:Use codeiginiter and ajax following the rules codeigniter按照 codeigniter 规则使用 codeiginiter 和 ajax
【发布时间】:2016-09-22 08:32:24
【问题描述】:

我正在努力按照它的创建方式使用 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);

}

任何帮助将不胜感激!

【问题讨论】:

    标签: php ajax codeigniter


    【解决方案1】:

    您可以使用帖子。修改您的 ajax 调用并传递如下数据。在此处查看文档https://api.jquery.com/jquery.post/

     data: { id: id, shop: shop }
    

    这个数据可以访问$this->input->post('id'); $this->input->post('shop');

    【讨论】:

      猜你喜欢
      • 2020-04-24
      • 2011-02-21
      • 1970-01-01
      • 2017-11-20
      • 1970-01-01
      • 2012-11-07
      • 1970-01-01
      • 2014-04-12
      • 2011-02-09
      相关资源
      最近更新 更多