javascript - dependent dropdown error Undefined index: TRANCHE codeigniter -
i have drop-down dependent on choices of other 2 drop-downs have debugged java script has error on error logs says,
undefined index: tranche
here controller
public function dependent_dropdown() { if(isset($_post['tranche']) || isset($_post['grade'])) { $data = $_post['tranche']; $data1 = $_post['grade']; $this->output ->set_content_type("application/json") ->set_output(json_encode($this->employeesalary_model->gettype($data, $data1))); } }
and here javascript
jquery(document).ready(function(){ $("#grade").change(function() { var tranche = {"tranche" : $('#tranche').val()}; var grade = {"grade" : $('#grade').val()}; console.log(tranche); console.log(grade); $.ajax({ type: "post", data: (tranche, grade), url: "<?php base_url(); ?>employeesalary/dependent_dropdown/", success: function(data){ var select = $('#sal_id'); select.html(''); $.each(data, function(i, option){ select.append("<option value='"+option.id+"'>"+option.amount+"</option>"); }); } }); }); });
please tell me problem , how can debug it. thanks
you have make array send both values.
var postdata = [ tranche , grade ]
$.ajax({ type: "post", data: json.stringify(postdata), ////stringify important url: "<?php base_url(); ?>employeesalary/dependent_dropdown/", success: function(data){ var select = $('#sal_id'); select.html(''); $.each(data, function(i, option){ select.append("<option value='"+option.id+"'>"+option.amount+"</option>"); }); } });
Comments
Post a Comment