0

this is the method I want to send data to it

function get_lesson($reshte,$poodeman){
        $this->load->model('dropdown_model');
        header('Content-Type: application/x-json; charset=utf-8');
        echo(json_encode($this->dropdown_model->get_lessons($reshte,$poodeman)));
    }

and this is the get_lessens() function in the model file.

  function get_lessons($reshte = null, $poodeman=NULL){
          $this->db->select('rlessid, title');

          if($reshte != NULL AND $poodeman!= NULL ){
              $this->db->where('reshteid', $reshte);
              $this->db->where('poodemanid', $poodeman);
          }

          $query = $this->db->get('tbllessons_root');

          $lessons = array();

          if($query->result()){
              foreach ($query->result() as $lesson) {
                  $lessons[$lesson->rlessid] = $lesson->title;
              }

          return $lessons;
          }else{
              return FALSE;
          }
    }

and this is my ajax call at the view file

var reshteid = $('#reshte').val();
 var poodemanid = $('#poodemanha').val();

$.ajax({
     type:"POST",
     url:"http://localhost/crud-grocery/index.php/examples/get_lesson/",//+reshte+"/"+poodeman,
     data: "reshte="+reshteid+"&poodeman="+poodemanid,
     success: function(lessons)
     {
        $.each(lessons,function(rlessid,title){
          var opt = $('<option />');
        opt.val(rlessid);
        opt.text(title);
        $('#lessons').append(opt);
        });
    }

});

as you see I am trying to chain options in the form but The problem comes up when I try to post (send) two parameters to the controller method any idea?

3
  • so ajax is not posting the data...? Or the problem is something else...? Commented Feb 23, 2012 at 6:31
  • it sends it when I post one parameter to the controller method, but it wont work when I include second paramether as post data. :( Commented Feb 23, 2012 at 6:32
  • you need to get POST values in your controller function not as parameters, since you are using POST method in Ajax Commented Feb 23, 2012 at 6:35

2 Answers 2

1

In your controller, you need to get POST values not as parameters:


//in controller
function get_lessons(){
...
//get POST values
$reshte = $this->input->post('reshte');
$poodeman = $this->input->post('poodeman');

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

2 Comments

That is true, I should go to sleep before i ask such questions again.
Happens sometimes, Glad to know you got it.. :)
0

You have to pass data as a javascript object literal:

...
data: {
  reshte: reshteid,
  poodeman: poodemanid
}
....

1 Comment

this is anther type of defining post data

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.