In this article you are able to see how to create sub site using Rest API.
We created a custom page and designed UI as per the below, Add this code in the script editor web part.
Create SharePoint Sub site using Client object model
<html>
<head>
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.0.min.js"></script>
<script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/4.0/1/MicrosoftAjax.js"></script>
<script type="text/javascript">
$(document).ready(function () {
bindButtonClick();
});
function bindButtonClick() {
alert('startbtnclick');
$("#register").on("click", function() {
var name = $("#txtSiteTitle").val();
var id = $("#txtSiteDescription").val();
var URL = $("#txtSiteURL").val();
if (name == '' || id == '' || URL == '') {
alert("Please fill all fields...!!!!!!");
} else {
createSite();
}
});
}
function createSite()
{
var siteTitle = $("#txtSiteTitle").val();
var siteDesc = $("#txtSiteDescription").val();
var siteUrl = $("#txtSiteURL").val();
$.ajax({
url: "https://dotnetsharepoint.com/Test/_api/web/webinfos/add",
type: "POST",
headers: {
"accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
data: JSON.stringify({
'parameters': {
'__metadata': {
'type': 'SP.WebInfoCreationInformation'
},
'Url': siteUrl ,
'Title': siteTitle ,
'Description': siteDesc ,
'Language': 1033,
'WebTemplate': 'sts',
'UseUniquePermissions': false
}
})
});
}
</script>
</head>
<body>
<div class="container">
<div class="main">
<form class="form" method="post" action="#">
<h2>Create Client sub Site</h2>
<label>Client Site Name :</label> <input type="text" name="dname" id="txtSiteTitle">
<label>Client Site Description:</label> <input type="text" name="demail" id="txtSiteDescription">
<label>Client Site URL: </label> <input type="text" name="durl" id="txtSiteURL">
<input type="button" name="register" id="register" value="Submit"> </form>
</div>
</body>
</html>
We created a custom page and designed UI as per the below, Add this code in the script editor web part.
Create SharePoint Sub site using Client object model
<html>
<head>
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.0.min.js"></script>
<script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/4.0/1/MicrosoftAjax.js"></script>
<script type="text/javascript">
$(document).ready(function () {
bindButtonClick();
});
function bindButtonClick() {
alert('startbtnclick');
$("#register").on("click", function() {
var name = $("#txtSiteTitle").val();
var id = $("#txtSiteDescription").val();
var URL = $("#txtSiteURL").val();
if (name == '' || id == '' || URL == '') {
alert("Please fill all fields...!!!!!!");
} else {
createSite();
}
});
}
function createSite()
{
var siteTitle = $("#txtSiteTitle").val();
var siteDesc = $("#txtSiteDescription").val();
var siteUrl = $("#txtSiteURL").val();
$.ajax({
url: "https://dotnetsharepoint.com/Test/_api/web/webinfos/add",
type: "POST",
headers: {
"accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
data: JSON.stringify({
'parameters': {
'__metadata': {
'type': 'SP.WebInfoCreationInformation'
},
'Url': siteUrl ,
'Title': siteTitle ,
'Description': siteDesc ,
'Language': 1033,
'WebTemplate': 'sts',
'UseUniquePermissions': false
}
})
});
}
</script>
</head>
<body>
<div class="container">
<div class="main">
<form class="form" method="post" action="#">
<h2>Create Client sub Site</h2>
<label>Client Site Name :</label> <input type="text" name="dname" id="txtSiteTitle">
<label>Client Site Description:</label> <input type="text" name="demail" id="txtSiteDescription">
<label>Client Site URL: </label> <input type="text" name="durl" id="txtSiteURL">
<input type="button" name="register" id="register" value="Submit"> </form>
</div>
</body>
</html>