I was just wondering if its a good idea to load more than one list in the same function as all of them use the same success callback , Code example:
function retrieveListItems() {
var clientContext = new SP.ClientContext.get_current();
var camlQuery = new SP.CamlQuery.createAllItemsQuery();
employerList = clientContext.get_web().get_lists().getByTitle('Employer Partners').getItems(camlQuery);
pocList = clientContext.get_web().get_lists().getByTitle('Points of Contact').getItems(camlQuery);
var lists = [employerList, pocList];
for (var i = 0; i < lists.length; i++) {
clientContext.load(lists[i]);
}
clientContext.executeQueryAsync(
Function.createDelegate(this, this.onQuerySucceeded),
Function.createDelegate(this, this.onQueryFailed)
);
}
The code runs on some occasions but fails with "The collection has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested." on other occasions.