0

I have been facing the problem with feature of Chrome. Just came to know after debugging.

An ajax call is made to get data from the server (which has been ordered from the server). But the problem is chrome is sorting the response JSON object. The below object has been taken from ajax response. But just sorts the object based on the key.

I don't have problem with IE or Firefox

{
    "83":"4",
    "65":"AV",
    "64":"AV HY",
    "59":"CAM",
    "10":"CAM Y H",
    "56":"CO",
    "18":"FJ CR"
}

After sorting the object looks like this

{
    "10":"CAM Y H",
    "18":"FJ CR",
    "56":"CO",
    "59":"CAM",
    "83":"4",
    "64":"AV HY",
    "65":"AV"
}

How can I fix this?

rink.attendant.6
  • 44,500
  • 61
  • 101
  • 156
Gopi
  • 909
  • 1
  • 8
  • 15
  • 1
    Order isn't guaranteed for object properties: see http://stackoverflow.com/questions/5525795/does-javascript-guarantee-object-property-order – rink.attendant.6 Jun 17 '15 at 15:46
  • Ok, So how can we fix this?? – Gopi Jun 18 '15 at 05:38
  • You can't fix something that isn't broken. If order is important, use an array. Perhaps it would be useful to explain *why* order is important in your case so people can possibly suggest alternative solutions. – rink.attendant.6 Jun 18 '15 at 05:43
  • Thanks for the response...Just have a look at the object defined in the question. The JSON object key is unordered in the response object but the value has been ordered in ASCII ascending order. As the chrome feature is sorting the keys, the values which has been ASCII sorded order gets scattered. Do i have to sort the values once again in client browser??? – Gopi Jun 18 '15 at 05:51

1 Answers1

0

I have done the sorting in the client side using array sort. Thanks for the input Rink

Gopi
  • 909
  • 1
  • 8
  • 15