Using JQuery Concept - Codeigniter


Snippet Code

Rate this page :
  [ 0 votes]

The jquery function is included in view part,the jquery function gets the text box value and pass the value to controllers add function and the value passed to model to add title into table.

View Part: jquery function: $(document).ready(function() { $('#submit').click(function() { var title = $("#title").val(); $.post("<?= site_url ('/product/add')?>" , { "title" : title}, function (data) { $('#add_div').html(data); }); }); }); HTML Part: <div id='add_div'> <input size='70' type=text name='title' id='title' value='' /> <input type='submit' value='Add' /> </div> Controller: function add() { if($_POST && $_POST['title'] != NULL) { $data['title'] = $this->input->xss_clean($_POST['title']); $this->product_model->add($data); } else redirect('product/view'); } function view() { $this->load->view('product/add_title'); } Model: function add($data) { $this->db->insert('title', $data);//title is table where we have to add title }


Ask Questions

Ask Question