Using JSOM I am trying to get the collection of all the webs(sub-sites) including the root web of a given site collection and display there title.
Below is the code snippet. But it throws error "get_allWebs()"property is not supported.
var context = new SP.ClientContext.get_current();
var web = context.get_web();
var siteColl = context.get_site();
var webSubSites = siteColl.get_allWebs();
context.load(webSubSites, 'Include(Title, ServerRelativeUrl)');
context.executeQueryAsync(
Function.createDelegate(this, function (sender, args) {
for (var x = 0; x < webSubSites.get_count(); x++) {
var subWeb = webSubSites.itemAt(x);
alert(subWeb.get_title());
}
}),
Function.createDelegate(this, function (sender, args) {
console.log('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}));
I am able to get all the subwebs\subsites, but not rootweb.