Created
March 22, 2014 09:22
-
-
Save vgrem/9703697 to your computer and use it in GitHub Desktop.
Create operation in SharePoint 2010 REST
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createListItem(webUrl,listName, itemProperties, success, failure) { | |
$.ajax({ | |
url: webUrl + "/_vti_bin/listdata.svc/" + listName, | |
type: "POST", | |
processData: false, | |
contentType: "application/json;odata=verbose", | |
data: JSON.stringify(itemProperties), | |
headers: { | |
"Accept": "application/json;odata=verbose" | |
}, | |
success: function (data) { | |
success(data.d); | |
}, | |
error: function (data) { | |
failure(data.responseJSON.error); | |
} | |
}); | |
} | |
//Usage: create task | |
var taskProperties = { | |
'TaskName': 'Order Approval', | |
'AssignedToId': 12 | |
}; | |
createListItem('https://contoso.sharepoint.com/project/','Tasks',taskProperties,function(task){ | |
console.log('Task' + task.TaskName + ' has been created'); | |
}, | |
function(error){ | |
console.log(JSON.stringify(error)); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment