Thursday, 19 June 2014

SharePoint REST Create New List Item


<script src="jquery-1.8.2.min.js"></script>
<script>
function create(lname, fname, wphone) {
$.ajax({
url: _spPageContextInfo.webServerRelativeUrl +
"/_api/web/lists/getByTitle('Contacts')/items",
type: "POST",
contentType: "application/json;odata=verbose",
data: JSON.stringify(
{
'__metadata': {
'type': 'SP.Data.ContactsListItem'
},
'Title': lname,
'FirstName': fname,
'WorkPhone': wphone
}),
headers: {
"accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
success: function () {
REST.FormFiller.clear();
},
error: function (err) {
alert(JSON.stringify(err));
}
});
}
</script>
view raw gistfile1.js hosted with ❤ by GitHub