Welcome Guest, Not a member yet? Register   Sign In
Is CI reordering my JSON encoded data?
#1

[eluser]3rdear[/eluser]
This is related to my previous post about multiple databases since it's the same project.

Here's the ajax function that calls the CI controller:

Code:
$('#domain_list').change(function(){
    var select = $(this);
    var value = select.val();
    
    $.post('http://localhost/ci/markets',
           {id: value},
           function(data){
               //console.log(data);
             var options;
             $.each(data, function(k, v){
               options += '<option value="' + k + '" >' + v + '</option>';
             })
             $('#market_list').html(options)
          },
           'json');
  });

Here's the stuff that the CI controller is doing

Code:
// controllers/markets.php

public function index()
{
        $this->load->model("Domain_model");
            
        $em = $this->Domain_model->getEntityManager($this->input->post('id'));
      
        $this->load->model("Market_model");
        $entities = $this->Market_model->getEntities($em);
        
        echo json_encode($entities);
}

Now ... both the $entities and json_encode($entities) are ordered alphabetically, according to market name, not market id, as per the SQL query in getEntities(), so I'm fairly certain that php isn't doing anything quirky. However, when it comes back to the javascript, the data object is reordered by market id, rather than market name, so I'm suspecting that something in the CI framework is changing the order because it's the only thing in between the echo and the javascript. Any help here?




Theme © iAndrew 2016 - Forum software by © MyBB