I am currently utilizing Spring as the backend for my application, along with Ajax to handle the fetching and posting of data. I have a situation where I am returning a HashMap from my controller and everything seems to be functioning correctly. However, upon receiving the data in my JavaScript file, the order of the data items is changing. What could be causing this issue?
For example, when I send
map.put("name","aaa");
map.put("name","bbb");
map.put("name","ccc");
In the JavaScript file, I observe a different order such as ccc, aaa, bbb. This changed order remains consistent and is not random.
Below are snippets of the code I am working with:
Controller
@RequestMapping(value = "/history", method = RequestMethod.GET)
public @ResponseBody Map<String, myModel> getHistory() {
Map<String, ChatModel> userInfo = md.getUserInfo(userId);
return userInfo;
}
Get method
$.ajax({
contentType: "application/json;charset=utf-8",
type : "GET",
url : "../Spring4MVCHelloWord/history/",
dataType : 'json',
success: function(data){
displayHistory(data);
},
error: function(xhr, status, error) {
console.log(xhr);
}
});