My using following script to create Sub site.
<script
src="//ajax.aspnetcdn.com/ajax/4.0/1/MicrosoftAjax.js" <br/>
type="text/javascript"><br/>
</script><br/>
<script<br/>
type="text/javascript" <br/>
src="/_layouts/15/sp.runtime.js"><br/>
</script><br/>
<script <br/>
type="text/javascript" <br/>
src="/_layouts/15/sp.js"><br/>
</script><br/>
<script type="text/javascript"><br/>
function myFunction()<br/>
{<br/>
alert('started');<br/>
var siteUrl = " ";<br/>
//get client context and root web<br/>
//var clientContext = new SP.ClientContext.get_current();<br/>
//var rootWeb = clientContext.site.rootWeb();<br/>
var clientContext = new SP.ClientContext(siteUrl);<br/>
var rootWeb = clientContext.site.rootWeb();<br/>
this.clientContext.load(rootWeb);<br/>
this.clientContext.executeQuery();<br/>
//set creation info<br/>
var WCI = new SP.WebCreationInformation();<br/>
WCI.set_webTemplate('sts#0');<br/>
WCI.set_description('Created Using CSOM');<br/>
WCI.set_title('Custom SubSite');<br/>
WCI.set_url(url);<br/>
WCI.set_useSamePermissionsAsParentSite(true);<br/>
WCI.set_language(1033);<br/>
this.rootWeb.get_webs().add(WCI);<br/>
this.rootWeb.update();<br/>
// save site and set callbacks<br/>
this.clientContext.load(this.rootWeb);<br/>
this.clientContext.executeQueryAsync(<br/>
Function.createDelegate(this, this.OnSiteCreationSuccess),<br/>
Function.createDelegate(this, this.Error));<br/>
}<br/>
</script><br/>
<p>Click the button to trigger a function.</p>
<button onclick="myFunction()">Click me</button>
</div>
My Facing following error.
- What url is undefined [WCI.set_url(url);]
- Script are not getting loaded MicrosoftAjax.js,sp.runtime.js and sp.js
- This script i have added inside script viewer web part SharePoint 2013.
Kindly provide me proper approach to create subsite using javascript object module.