Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. POST https://company.sharepoint.com/sites/siteName/_api/web/lists/getbytitle('Employees')/items 403 (FORBIDDEN)
  2.  
  3. function GetListItemsFromSPList() {
  4. var siteUrl = "https://company.sharepoint.com/sites/siteName/";
  5. $('#listitems').empty();
  6. $.ajax({
  7. url: siteUrl + "_api/web/lists/getbytitle('Employees')/items/",
  8. method: "GET",
  9. headers: { "Accept": "application/json; odata=verbose" },
  10. success: function (data) {
  11.  
  12. var listItems = data.d.results;
  13. listItems.forEach(function (entry) {
  14. var node = document.createElement("LI");
  15. var textnode = document.createTextNode(entry.UserID);
  16. node.appendChild(textnode);
  17. document.getElementById("listitems").appendChild(node);
  18. });
  19. },
  20. error: function (data) {
  21. alert("Error: " + data)
  22. }
  23. });}
  24.  
  25. function AddListItem() {
  26. var siteUrl = "https://company.sharepoint.com/sites/siteName/";
  27. $.ajax
  28. ({
  29. url: siteUrl + "_api/web/lists/GetByTitle('Employees')/items",
  30. type: "POST",
  31. data: JSON.stringify
  32. ({
  33. __metadata:
  34. {
  35. type: "SP.Data.EmployeesListItem"
  36. },
  37. UserID: "US-USERID",
  38. Position: "Position Name"
  39. }),
  40. headers:
  41. {
  42. "Accept": "application/json;odata=verbose",
  43. "Content-Type": "application/json;odata=verbose",
  44. "X-RequestDigest": $("#__REQUESTDIGEST").val(),
  45. "X-HTTP-Method": "POST"
  46. },
  47. success: function(data, status, xhr)
  48. {
  49. GetListItemsFromSPList();
  50. },
  51. error: function(xhr, status, error)
  52. {
  53. alert("Error");
  54. }
  55. });}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement