I wonder if we can do something like
var joinedJSON;
$.get("server.json?action=type&type=image", function(json) {joinedJSON +=json ; }
$.get("server.json?action=type&type=jpg", function(json) {joinedJSON +=json ; }
$.get("server.json?action=type&type=png", function(json) {joinedJSON +=json ; }
$.get("server.json?action=type&type=tiff", function(json) {joinedJSON +=json ; }
while each request will provide us with say such JSON data:
[
{
"href": "bf051e8675b11c72eec781e855593589a086d2295378b96a8b7269c31b8fa673.user.file",
"title": "Привет Мир.jpg",
"user_name": "Oleg.Jakushkin@gmail.com",
"modified": "2012-01-16 07:24:11",
"is_public": 0,
"size": 65516
},
{
"href": "abd01be9a0830579d6366e48fc0c48d4c7cc350d80719843ca84c782346626f6.user.file",
"title": "",
"user_name": "Oleg.Jakushkin@gmail.com",
"modified": "2012-01-16 07:24:19",
"is_public": 0,
"size": 89782
},
{
"href": "0a27fd3b563b2877c3a072648e0f7c2a57539f3aba4ce688c7774eca6b70774e.user.file",
"title": "Привет Мир 2.jpg",
"user_name": "Oleg.Jakushkin@gmail.com",
"modified": "2012-01-16 07:24:29",
"is_public": 1,
"size": 58574
}
]
Will we get one long array having in mind that some items may repeat (multymap in C++) as result?
Note that the add operation
+on Arrays are not defined in Javascript. Instead of extending an array by another one, it coerces them into strings and concatenated.You should use
concatinsteadAlso, note that
$.getis an asynchronous function. If you simply serialize them in the code you provided, you will not know when all the requests are finished. Instead, you should try to issue each request in the callback function of the previous one. This ensures that each request is made after the the response from the previous one is received.If you find the nested callbacks ugly, you may consider using the async module.