I have a function which is returning the list of city names associated to city_id
ordered by city name.
I want to show them in a select box. In Firefox (23.0.1) it is working fine even with order. But in case of IE (10) and chrome (29.0.1547.66 m) the order is not correct. I am using PHP and zend framework. My code:
$cities = $countryCityModel->getCities($country);
print json_encode(array('status'=>'Success',
'data'=>$cities)
);
public function getCities($countryId){
if(!$countryId)
return false;
$mdb = $this->getOldDbAdapter();
$sql = $mdb->select()
->from('cities', array('city_id','city'))
->where('country_id = ?', $countryId)
->order("city");
return $mdb->fetchPairs($sql);
}
$.ajax({
url : baseUrl + '/lead/index/get-cities',
dataType : 'json',
data : {
country:country_id
},
beforeSend : function(){
$("#holder_popup").show();
},
complete: function(){
$("#holder_popup").hide();
},
success : function(res) {
var sbuOptions = "<option value=''>--SELECT--</option>"
if(res.status == 'Success'){
for(i in res.data){
sbuOptions += "<option value='"+i+"'>"+res.data[i]+"</option>";
}
$("#city").html(sbuOptions);
}else{
$("#city").html(sbuOptions);
alert(res.msg);
}
},
error : function(jqXHR, exception) {
}
});
The returned value is like the following:
{
"status":"Success",
"data":{
"53029":"DURRES",
"53331":"ELBASAN",
"40239":"FIER",
"16235":"KAMEZ",
"42191":"KAVAJE",
"41375":"KUKES",
"53581":"PESHKOPI",
"57686":"SHIJAK",
"56756":"SHKODER",
"4496":"TIRANA",
"41342":"VLORE",
"19454":"VORE"
}
}
Please help me, how to resolve this issue?