jquery-related-selects
jquery-related-selects copied to clipboard
Sort order of elements not maintained with JSON in Google Chrome
Note that the $.each() function under Chrome appears to not respect the order of the elements as defined in the JSON object returned by the server. When the $.each() is used to add each select item to the dropdown on the successful AJAX call, they become arranged in order of the value for each element.
For example, if I return the following from the web service:
{"2":"First Item","1":"Second Item","3":"Third Item"}
In Chrome, they will appear in the dropdown in the order:
- Second Item
- First Item
- Third Item
In Firefox the order is properly maintained. Not sure about other browsers.
I can confirm this using:
- Firefox 7 the order is just like in the JSON object
- Chrome 14 the order is sorted by the key