使用Cjax在CodeIgniter中POST数据

时间:2014-08-10 10:00:00

标签: php ajax codeigniter

我试图在CodeIgniter中使用Cjax发布一些数据。

我的观点是:

<?php
  require_once(FCPATH . 'ajaxfw.php');
  $ajax->click('#subscribesubmit' , $ajax->form('ajax.php?subscriber/add/'));
?>
<div class="col-md-4">
    <form class="form-inline subscribe-box" role="form" method="post">
      <div class="form-group">
        <label class="sr-only" for="subscribemail">Email address</label>
        <input type="text" class="form-control" id="subscribemail" name="subscribemail" placeholder="Enter email">
      </div>
      <button type="submit" class="btn btn-default" id="subscribesubmit">Subscribe</button>
    </form>
</div>

此视图加载到控制器索引()中。

我的subscriber控制器:

class Subscriber extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->library('email');
        $this->load->model('subscriber_model');
        require_once(FCPATH.'ajaxfw.php');

    }

    public function add($subscribemail) {
        $ajax = ajax();
        //$email = $this->input->post('subscribemail');
        echo $subscribemail;
        $data['status'] = $this->subscriber_model->new_subscriber($subscribemail);
        }
    }

}

2 个答案:

答案 0 :(得分:0)

试试这个:

代码块中的

替换为:

require_once(FCPATH . 'ajax.php');

而不是:

require_once(FCPATH . 'ajaxfw.php');

答案 1 :(得分:0)

你应该包含ajax.php而不是ajaxfw.php(如果需要,ajax.php将自己包含ajaxfw.php)