i want to retrive this json in my select box this is my controller code and
public function getDistrictById()
{
$StateId=$this->input->post('StateId');
$District=$this->Main_model->getDistrictListByStateId($StateId);
//echo json_encode($District);
foreach($District as $d)
{
$rows[]=array("id"=>$d->DistrictId,"name"=>$d->DistrictName);
}
print json_encode($rows);
}
here is my jquery/ajax code
<script>
function getDistrict()
{
var StateId=$('#state option:selected').val();
$.ajax({
url:'<?php echo base_url()?>Home/getDistrictById',
type: 'POST',
dataType:"json",
data: {StateId:StateId},
success: function(response){
// $('#District').html(response);
console.log(response);
},
error: function(){
alert("Fail");
}
});
}
</script>
the console.log(response); give me the exact output but i am not sure how to appen this in to a select box. i have already try How do I add options to a DropDownList using jQuery? and many more plz help...