![](/img/trans.png)
[英]Error creating communication site in Sharepoint Online via REST and Javascript
[英]Creating SharePoint Site with JavaScript
我正在尝试使用JSOM在按钮单击上创建一个子站点(网站)。 该功能正在起作用-只要使用给定的配置创建站点即可。 但是,尽管实际上确实在创建站点,但ExecuteQueryAsync调用始终会路由到故障功能。 相关代码如下:
var ctx = SP.ClientContext.get_current();
var web = ctx.get_web();
var webCreationInfo = new SP.WebCreationInformation();
webCreationInfo.set_title(portalName); //note: this variable is defined elsewhere
webCreationInfo.set_description('');
webCreationInfo.set_language(1033);
webCreationInfo.set_url(webUrl); //note: this variable is defined elsewhere
webCreationInfo.set_useSamePermissionsAsParentSite(false);
webCreationInfo.set_webTemplate(templateGuid); //note: this variable is defined elsewhere
web.get_webs().add(webCreationInfo);
web.update();
ctx.load(web);
ctx.executeQueryAsync(
function() {
alert("Created Site");
},
function(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
);
这包括在我的代码的其他地方定义的几个变量,但这不应该成为我的问题的一部分。 使用正确的模板,名称和URL,可以正确创建该网站。
尽管网站已正确创建,但“请求失败”警报始终会为我弹出。 args.get_message()的值为“服务器的意外响应”,而args.get_stackTrace()的值为“ null”。
这里的问题实际上是由于按钮而不是上面的代码。 我需要添加'event.preventDefault();' 到我的onClick函数的开始。 否则,页面将尝试刷新-这种更新的速度比提供站点的速度快得多。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.