title: Display sharepoint library items with Javascript
body: <p>I have 3 libraries and i would like to display the library items names. If I want to display the items of only one library, everything is ok, but if I'm looking for the items of two or more libraries, it still shows me only the Items of ONE library. What is wrong in my code? </p>
  
  <pre><code>    &lt;p id="AInfo"&gt;library A Items&lt;/p&gt;
      &lt;p id="BInfo"&gt;library B Items&lt;/p&gt;
      &lt;p id="CInfo"&gt;library C Items&lt;/p&gt;
  
      &lt;script type="text/javascript"&gt;
  
          jQuery(document).ready(function(){ExecuteOrDelayUntilScriptLoaded(fill, "sp.js"); });
  
          var siteUrl = '/Example/test/';
          liblist = new Array("A", "B", "C"); //list of the libraries
          var i=0;
          var lib;
  
          function fill(){
              while (i&lt;3){
                  lib = liblist[i];
                  alert(lib);
                  retrieveListItemsInclude();
                  i++;
              }
          }
  
  
          function retrieveListItemsInclude() {
  
  
              var clientContext = new SP.ClientContext(siteUrl);
              var oList = clientContext.get_web().get_lists().getByTitle(lib);
  
              var camlQuery = new SP.CamlQuery();
              camlQuery.set_viewXml('&lt;View&gt;&lt;RowLimit&gt;100&lt;/RowLimit&gt;&lt;/View&gt;');
              this.collListItem = oList.getItems(camlQuery);
  
              clientContext.load(collListItem, 'Include(Id, DisplayName, HasUniqueRoleAssignments)');
  
              clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
          }
  
  
              function onQuerySucceeded(sender, args) {
                  var listItemInfo = '';
                  var listItemEnumerator = collListItem.getEnumerator();            
  
                  while (listItemEnumerator.moveNext()) {
                      var oListItem = listItemEnumerator.get_current();
                      listItemInfo += oListItem.get_displayName()+ '&lt;br&gt;';
                  }
  
                  var x = listItemInfo.toString();
                  document.getElementById(lib+"Info").innerHTML = x;
          }
  
  
          function onQueryFailed(sender, args) {
  
              var x = 'Request failed. ' + args.get_message() + '\n' + args.get_stackTrace();
              document.getElementById(lib+"Info").innerHTML = x;  
          }
  
      &lt;/script&gt;
  </code></pre>