1

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;}
1
  • try using var datas= {tadada: 'service_type='+ service_type}; and reference tadada as POST variable you receive. Commented Feb 15, 2014 at 14:59

3 Answers 3

1

Use:

$('.select_service').click(
            function(){
             var service_type = this.id.substr(0,7);
                    var datas= {tadada: '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;
            }

        );

In php you will the tadada as POST variable

Sign up to request clarification or add additional context in comments.

2 Comments

make sure that, in php, instead of $select_service =$this->input->post('data', TRUE); you use $select_service =$this->input->post('tadada', TRUE);
Hm, your code it's a bit complicated. Try with the next answer, if it's still now working check if you are sending the post to a page and it's sent successfully. Then, as you did, try to figure out how the data you receive looks like.
1

Your post key is service_type not data

$select_service =$this->input->post('service_type', TRUE);

7 Comments

I change it.. but still not working. I think jquery part is ok.. Uncommand this line window.location.href=base_url + 'edit_profile'; then it go to new url. still some more error in recieving part..
what is the value of base_url
I think no error in base_url I use redirect(base_url().'edit_profile/'); inside index() function it redirect.. to edit_profile page..
Try url: "<?php echo base_url() ?>select_service",
I try it but still not working. I think code does not enter inside if($this->input->post('service_type')) statement...
|
0

Try:

$('.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: { data: datas },
                    success: function(msg)
                    {
                    //window.location.href=base_url + 'edit_profile';

                    }
                }); 
            return false;
        }

    );

An get the value of data in your controller with $this->input->post('data')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.