Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- POST https://company.sharepoint.com/sites/siteName/_api/web/lists/getbytitle('Employees')/items 403 (FORBIDDEN)
- function GetListItemsFromSPList() {
- var siteUrl = "https://company.sharepoint.com/sites/siteName/";
- $('#listitems').empty();
- $.ajax({
- url: siteUrl + "_api/web/lists/getbytitle('Employees')/items/",
- method: "GET",
- headers: { "Accept": "application/json; odata=verbose" },
- success: function (data) {
- var listItems = data.d.results;
- listItems.forEach(function (entry) {
- var node = document.createElement("LI");
- var textnode = document.createTextNode(entry.UserID);
- node.appendChild(textnode);
- document.getElementById("listitems").appendChild(node);
- });
- },
- error: function (data) {
- alert("Error: " + data)
- }
- });}
- function AddListItem() {
- var siteUrl = "https://company.sharepoint.com/sites/siteName/";
- $.ajax
- ({
- url: siteUrl + "_api/web/lists/GetByTitle('Employees')/items",
- type: "POST",
- data: JSON.stringify
- ({
- __metadata:
- {
- type: "SP.Data.EmployeesListItem"
- },
- UserID: "US-USERID",
- Position: "Position Name"
- }),
- headers:
- {
- "Accept": "application/json;odata=verbose",
- "Content-Type": "application/json;odata=verbose",
- "X-RequestDigest": $("#__REQUESTDIGEST").val(),
- "X-HTTP-Method": "POST"
- },
- success: function(data, status, xhr)
- {
- GetListItemsFromSPList();
- },
- error: function(xhr, status, error)
- {
- alert("Error");
- }
- });}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement