Saturday, 12 July 2014

SharePoint REST Create New List Item

create: function (varName) {
$.ajax({
url: _spPageContextInfo.webServerRelativeUrl +
"/_api/web/lists/getByTitle('MyListName')/items",
type: "POST",
contentType: "application/json;odata=verbose",
data: JSON.stringify(
{
'__metadata': {
'type': 'SP.Data.MyListNameListListItem'
},
'Title': varName
}),
headers: {
"accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
success: function () {
alert("Sucess");
},
error: function (err) {
alert(JSON.stringify(err));
}
});
}