I am trying to get a site title property using JSOM, but i get can't read prperty 'title' of undefined. Can someone help me understand this error message?
function getRootWeb() {
//Get and load a reference to the root web of the current site collection.
var ctx = new SP.ClientContext("http://Server/sites/sitecollection/");
var site = ctx.get_site();
var rootWeb = site.get_rootWeb();
ctx.load(rootWeb);
//Ask SharePoint to pull data for us
ctx.executeQueryAsync(onQuerySucceed,onQueryFailed);
};
//Function executed on success
function onQuerySucceed() {
alert(this.rootWeb.get_title());
};
//Function executed on failure
function onQueryFailed(sender, args) {
alert('Unable to retrieve data from the SharePoint. Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
};