I don't know if I get your question, but maybe something like that works for you: (not tested)
var Queue = function(callback) {
this.count = 0;
this.done = 0;
this.callback = callback;
};
Queue.prototype.oneDone = function() {
if (++this.done == this.count) {
this.callback();
}
}
Queue.prototype.process = function(data, callback) {
this.count = data.length;
for (i in data ) {
callback(data[i], this);
}
};
$.ajax({
type: 'GET',
dataType: 'json',
url: "get_data.htm",
async : false,
success: function(data, textStatus) {
var myQueue = new Queue(function() {
alert(resultArray); //here i want to send the response to server side
});
myQueue.process(data, function(item, queue) {
searchClick(item.firstName, item.lastName, queue);
});
},
error: function(xhr, textStatus, errorThrown){
alert('request failed');
}
});
function searchClick(firstName, secondName, queue) {
if (!IN.ENV.auth.oauth_token) {
alert("You must login w/ LinkedIn to use the Search functionality!");
return;
}
IN.API.PeopleSearch()
.fields("id", "firstName", "lastName","emailAddress","headline","industry","pictureUrl","positions",
"summary","numConnections")
.params({
"first-name": firstName,
"last-name": secondName
})
.result(function(result, metadata) {
for (i in result.people.values) {
try {
resultArray[i] = result.people.values[i];
} catch(err) {
alert(err);
}
}
if (queue) {
queue.oneDone();
}
});
}