Ajax返回数据失败

I am using javascript to fetch values for a select option - triggered by a change in previous select option.

        $('#groupid, #lbl_groupid').hide();
        $('#subgroupid, #lbl_subgroupid').hide();

        $('#managerid').change(function(){
            var manager_id = $('#managerid').val();                
            if (manager_id != "")
            {
            var post_url = "nab1/index.php/main_page/get_groups/" + manager_id;

            $.ajax({
              type: "POST",
              url: post_url,
              success: function(group_list) //we're calling the response json array 'cities'
              {
                $('#groupid').empty();
                $('#groupid, #lbl_groupid').show();

                $.each(data,function(id,value) 
                {

                  var opt = $('<option />'); // here we're creating a new select option for each group
                      opt.val(id);
                      opt.text(value);
                      $('#groupid').append(opt); 
            });
           } //end success
     }); //end AJAX
} else {
    $('#groupid').empty();
    $('#groupid, #lbl_groupid').hide();
}//end if
}); //end change 

When i am calling function in the browser get_groups along with a parameter i am getting {"4":"nab_group_1_1","6":"nab_group_2_1"}

however options are not being populated.

I have following code in controller

function get_groups()
{
    $manager = $this->uri->segment(3);

    $group_list = $this->models_personnel->get_groups_by_managerid($manager);
    //header('Content-Type: application/x-json; charset=utf-8');    
    echo  json_encode($group_list);

}  

can somebody please tell whats wrong.

When i am using return from ajax call in an alert its showing me code of the current page. Please tell me how can i effectively implement this so that select option are properly populated. Thanks in advance

You have a mistake in the code here:

$.each(data,function(id,value) 

That should be:

$.each(group_list,function(id,value)

Because you named the returned data group_list in here:

success: function(group_list)

Also, add dataType: "json", to your ajax call:

$.ajax({
    type: "POST",
    url: post_url,
    dataType: "json",
    // etc