I want to identify which button is press. And store the substring(service type) of id of button in database. Using jquery I got the substring of id of button. In next step I want to sent the value to controller. Using following codes I try to do it. But don't get any value inside the controller...
Jquery:
$('.select_service').click(
function(){
var service_type = this.id.substr(0,7);
var datas='service_type='+ service_type;
alert(datas);//this work fine
$.ajax({
type: "POST",
url: base_url + 'select_service',
data: datas,
success: function(msg)
{
//window.location.href=base_url + 'edit_profile';
}
});
return false;
}
);
select_service.php view file
...............
<div class="row">
<div class="col-sm-6 col-sm-offset-4">
<p class="submit"><input type="submit" class="select_service" name="register" value="599 /-pm" id="list_pm_bt"></p>
</div>
</div>
<div class="row">
<div class="col-sm-6 col-sm-offset-2">
<p>Half Yearly:</p>
</div>
<div class="col-sm-6 col-sm-offset-4">
<p class="submit"><input type="submit" class="select_service" name="register" value=" 3299 /- " id="list_hy_bt"></p>
</div>
</div>
<div class="row">
<div class="col-sm-6 col-sm-offset-2">
<p>Annual:</p>
</div>
<div class="col-sm-6 col-sm-offset-4">
<p class="submit"><input type="submit" class="select_service" name="register" value=" 5999 /- " id="list_an_bt"></p>
</div>
</div>
..............
select_service.php controller
public function index()
{
$this->load->view('select_service');
$select_service =$this->input->post('data', TRUE);
echo "select controller";//it work
echo $select_service;//nothing to display
if($this->input->post('data'))
{
echo "update data";//it does not work
$this->service($select_service);
}
}
public function service($select){
$select_service =$select;
$array = array('service_type'=>$select_service);
$result = $this->register_model->add_service($array);
redirect(base_url().'edit_profile/');
}.......
register_model.php
function add_service($array){
$email=$this->session->flashdata('email');
$this->db->select("email");
$this->db->from("store");
$this->db->where('email', $email);
$query=$this->db->get();
if ($query->num_rows() > 0){
echo $query->num_rows();
}else{
$store_id = $this->db->update('store',$array);
return 1;}