Solution:
Here I create 2 variables as follow:
1)
url: REST
APi with list name
2)
data:
this variable contain the column name with respective values
var url =
"/_api/Web/Lists/GetByTitle('CRUDList')/Items";
var data = {
__metadata: { 'type': 'SP.Data.CRUDListListItem' },
Title: 'Some title'
};
Function:
function addNewItem(url, data) {
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl
+ url,
type:
"POST",
headers: {
"accept":
"application/json;odata=verbose",
"X-RequestDigest":
$("#__REQUESTDIGEST").val(),
"content-Type":
"application/json;odata=verbose"
},
data:
JSON.stringify(data),
success:
function (data) {
console.log(data);
},
error:
function (error) {
alert(JSON.stringify(error));
}
});
}
Function call:
addNewItem(url,data);
Feel free to revert in-case of any query...
Product Applies To:
· SharePoint Server 2013
· SharePoint Foundation 2013
No comments:
Post a Comment