In this article, I have explained how to perform create, read, update, and delete operations on SharePoint list items using HTTP requests.

HTTP Request Use
GET This method helps to fetch the information fromSharepoint list
POST This method helps to create or update the list items in sharepoint listPUT: Required all the object properties to update the resourcesMerge: Optional to required all the object properties to update the resources
PUT/MERGE This method helps to update the existing object using X-HTTP method
DELETE This method helps to delete the object from sharepoint list

Open sharepoint site,

Create a list name “Employee” to play Create, Read, Update, Delete Operations using HTTP RequestsP


“POST” method used to create Item in the sharepoint list

URL

http://<Sharepoint SiteURL>/_api/web/lists/Getbytitle(listname)/items


  1. function createListItem() {
  2. //Fetch the values from the input elements
  3. var eName = $('#txtempname').val();
  4. var eDesg = $('#txtdesignation').val();
  5. var eEmail = $('#txtemail').val();
  6. var eMobile = $('#txtmobile').val();
  7. var eBloodGroup = $('#txtbloodgrp').val();
  8. var eComAddress = $('#txtaddress').val();
  9. var eEmergency = $('#txtemergency').val();
  10. $.ajax({
  11. async: true, // Async by default is set to “true” load the script asynchronously
  12. // URL to post data into sharepoint list
  13. url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('Employee')/items",
  14. method: "POST", //Specifies the operation to create the list item
  15. data: JSON.stringify({
  16. '__metadata': {
  17. 'type': 'SP.Data.EmployeeListItem' // it defines the ListEnitityTypeName
  18. },
  19. //Pass the parameters
  20. 'EmployeeName': eName,
  21. 'Designation': eDesg,
  22. 'Email': eEmail,
  23. 'Mobile': eMobile,
  24. 'BloodGroup': eBloodGroup,
  25. 'CommunicationAddress': eComAddress,
  26. 'EmergencyContact': eEmergency
  27. }),
  28. headers: {
  29. "accept": "application/json;odata=verbose", //It defines the Data format
  30. "content-type": "application/json;odata=verbose", //It defines the content type as JSON
  31. "X-RequestDigest": $("#__REQUESTDIGEST").val() //It gets the digest value
  32. },
  33. success: function(data) {
  34. swal("Item created successfully", "success"); // Used sweet alert for success message
  35. },
  36. error: function(error) {
  37. console.log(JSON.stringify(error));
  38. }
  39. })
  40. }

"GET" Method used to Fetch the list items from the sharepoint list

URL

http://<Sharepoint SiteURL>/_api/web/lists/Getbytitle(listname)/items
  1. function getItems() {
  2. $.ajax({
  3. async: true, // Async by default is set to “true” load the script asynchronously
  4. url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('Employee')/items", // URL to fetch data from sharepoint list
  5. method: "GET", //Specifies the operation to fetch the list item
  6. headers: {
  7. "accept": "application/json;odata=verbose", //It defines the Data format
  8. "content-type": "application/json;odata=verbose" //It defines the content type as JSON
  9. },
  10. success: function(data) {
  11. data = data.d.results;
  12. //Iterate the data
  13. $.each(data, function(index, value) {
  14. var html = "<tr><td>" + value.EmployeeName + "</td><td>" + value.Designation + "</td><td>" + value.Email + "</td>
  15. <td>" + value.BloodGroup + "</td><td>" + value.CommunicationAddress + "</td>
  16. <td>" + value.EmergencyContact + "</td><td>" + value.Mobile + "</td>
  17. <td>
  18. <a href='#' data-target='#ModalForUpdateEmployee' data-toggle='modal' onclick='edit(" + value.Id + ")'>
  19. <img src='https://sharepointtechie.sharepoint.com/sites/automatedwiki/SiteAssets/CRUD/003-edit-document.png'>
  20. </a></td><td><a href='#' onclick='deleteItem(" + value.Id + ");'>
  21. <img src='https://sharepointtechie.sharepoint.com/sites/automatedwiki/SiteAssets/CRUD/001-delete.png'></a></td>
  22. </tr>";
  23. $('.table tbody').append(html); //Append the HTML
  24. });
  25. table = $('#subsiteList').DataTable(); //initialize the datatable
  26. },
  27. error: function(error) {
  28. console.log(JSON.stringify(error));
  29. }
  30. })
  31. }
"MERGE" Method used to perform update the item in sharepoint list

URL

http://<Sharepoint SiteURL>/_api/web/lists/Getbytitle(listname)/items(itemid)
  1. function update(uId) {
  2. //Fetch the values from the input elements
  3. var eName = $('#txtempnames').val();
  4. var eDesg = $('#txtdesignations').val();
  5. var eEmail = $('#txtemails').val();
  6. var eMobile = $('#txtmobiles').val();
  7. var eBloodGroup = $('#txtbloodgrps').val();
  8. var eComAddress = $('#txtaddresss').val();
  9. var eEmergency = $('#txtemergencys').val();
  10. $.ajax({
  11. url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('Employee')/items(" + uId + ")",
  12. method: "POST",
  13. data: JSON.stringify({
  14. '__metadata': {
  15. 'type': 'SP.Data.EmployeeListItem'
  16. },
  17. 'EmployeeName': eName,
  18. 'Designation': eDesg,
  19. 'Email': eEmail,
  20. 'Mobile': eMobile,
  21. 'BloodGroup': eBloodGroup,
  22. 'CommunicationAddress': eComAddress,
  23. 'EmergencyContact': eEmergency
  24. }),
  25. headers: {
  26. "accept": "application/json;odata=verbose",
  27. "content-type": "application/json;odata=verbose",
  28. "X-RequestDigest": $("#__REQUESTDIGEST").val(),
  29. "IF-MATCH": "*", //Overrite the changes in the sharepoint list item
  30. "X-HTTP-Method": "MERGE" // Specifies the update operation in sharepoint list
  31. },
  32. success: function(data) {
  33. swal( "Item Updated successfully", "success");
  34. //Reninitialize the datatable
  35. if ($.fn.DataTable.isDataTable('#subsiteList')) {
  36. $('#subsiteList').DataTable().destroy();
  37. }
  38. $('#subsiteList tbody').empty();
  39. //Bind the data into datatable
  40. getItems();
  41. },
  42. error: function(error) {
  43. console.log(JSON.stringify(error));
  44. }
  45. })
  46. }
"DELETE" method used to perfoms delete items in the sharepoint list
URL

http://<Sharepoint SiteURL>/_api/web/lists/Getbytitle(listname)/items(itemid)

  1. function deleteItem(value) {
  2. $.ajax({
  3. url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('Employee')/items(" + value + ")",
  4. method: "POST",
  5. headers: {
  6. "accept": "application/json;odata=verbose",
  7. "content-type": "application/json;odata=verbose",
  8. "X-RequestDigest": $("#__REQUESTDIGEST").val(),
  9. "IF-MATCH": "*",
  10. "X-HTTP-Method": "DELETE"
  11. },
  12. success: function(data) {
  13. swal("Deleted!", "Item Deleted successfully", "success");
  14. //Renitialize the datatable
  15. if ($.fn.DataTable.isDataTable('#subsiteList')) {
  16. $('#subsiteList').DataTable().destroy();
  17. }
  18. $('#subsiteList tbody').empty();
  19. getItems();
  20. },
  21. error: function(error) {
  22. console.log(JSON.stringify(error));
  23. }
  24. })
  25. }
HTML Code
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <script src="https://sharepointtechie.sharepoint.com/sites/automatedwiki/SiteAssets/CRUD/jquery-1.12.4.js"></script>
  5. <script src="https://sharepointtechie.sharepoint.com/sites/automatedwiki/SiteAssets/CRUD/jquery.dataTables.min.js"></script>
  6. <script src="https://sharepointtechie.sharepoint.com/sites/automatedwiki/SiteAssets/CRUD/dataTables.bootstrap.min.js"></script>
  7. <script src="https://sharepointtechie.sharepoint.com/sites/automatedwiki/SiteAssets/CRUD/bootstrap.min.js"></script>
  8. <link rel="stylesheet" type="text/css" href="https://sharepointtechie.sharepoint.com/sites/auto/SiteAssets/CRUD/dataTables.bootstrap.min.css" />
  9. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
  10. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.css" />
  11. <script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.js" type="text/javascript"></script>
  12. <script src="https://sharepointtechie.sharepoint.com/sites/automatedwiki/SiteAssets/CRUD/Script.js"></script>
  13. <link rel="stylesheet" href="https://sharepointtechie.sharepoint.com/sites/automatedwiki/SiteAssets/CRUD/Style.css" type="text/css" /> </head>
  14. <body>
  15. <div class="container">
  16. <div id="row4" class="row nopadding ">
  17. <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 form-horizontal padLeftRight">
  18. <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 pleft0 pright0">
  19. <div class="announcment paddingwebpart " style="background:white;">
  20. <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 pleft0 pright0">
  21. <h5 id="BtnAlign"> <a class="addbtn" target="_blank" style="color:white; text-decoration:none" data-target="#ModalForNewProject" data-toggle="modal">New Employee</a> </h5> <br> </div>
  22. <table id="subsiteList" class="table table-striped table-bordered">
  23. <thead>
  24. <tr>
  25. <th>Employee Name</th>
  26. <th>Designation</th>
  27. <th>Address</th>
  28. <th>Email</th>
  29. <th>Blood Group</th>
  30. <th>Emergency Contact</th>
  31. <th>Mobile</th>
  32. <th>Edit</th>
  33. <th>Delete</th>
  34. </tr>
  35. </thead>
  36. <tbody></tbody>
  37. </table>
  38. </div>
  39. </div>
  40. </div>
  41. </div>
  42. <div class="modal fade" id="ModalForNewProject" role="dialog" title="Create new Project">
  43. <div class="modal-dialog">
  44. <fieldset>
  45. <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 cls-contriute">
  46. <h5 class="contributtitle">Add Employee Information</h5>
  47. </div>
  48. </fieldset>
  49. <div id="ModelBody">
  50. <div class="form-horizontal well bs-component cls-divthoug" id="ModalValidation">
  51. <fieldset id="bodymodal">
  52. <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 form-group"> <label class="col-lg-4 col-md-4 col-sm-4 col-xs-4 cls-thought">Employee Name
  53. <span class="red">*</span>
  54. </label>
  55. <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8"> <input class="form-control" type="text" id="txtempname" /> <span class="ErMsg" id="ProNmMsg">Please fill out this field!</span> </div>
  56. </div>
  57. <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 form-group"> <label class="col-lg-4 col-md-4 col-sm-4 col-xs-4 cls-thought">Designation
  58. <span class="red">*</span>
  59. </label>
  60. <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8"> <input class="form-control" type="text" id="txtdesignation" /> <span class="ErMsg" id="ProNmMsg">Please fill out this field!</span> </div>
  61. </div>
  62. <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 form-group"> <label class="col-lg-4 col-md-4 col-sm-4 col-xs-4 cls-thought">Email
  63. <span class="red">*</span>
  64. </label>
  65. <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8"> <input class="form-control" type="text" id="txtemail" /> <span class="ErMsg" id="ProNmMsg">Please fill out this field!</span> </div>
  66. </div>
  67. <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 form-group"> <label class="col-lg-4 col-md-4 col-sm-4 col-xs-4 cls-thought">Mobile
  68. <span class="red">*</span>
  69. </label>
  70. <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8"> <input class="form-control" type="text" id="txtmobile" /> <span class="ErMsg" id="ProNmMsg">Please fill out this field!</span> </div>
  71. </div>
  72. <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 form-group"> <label class="col-lg-4 col-md-4 col-sm-4 col-xs-4 cls-thought">Blood Group
  73. <span class="red">*</span>
  74. </label>
  75. <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8"> <input class="form-control" type="text" id="txtbloodgrp" /> <span class="ErMsg" id="ProNmMsg">Please fill out this field!</span> </div>
  76. </div>
  77. <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 form-group"> <label class="col-lg-4 col-md-4 col-sm-4 col-xs-4 cls-thought">Address for communication
  78. <span class="red">*</span>
  79. </label>
  80. <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8"> <input class="form-control" type="text" id="txtaddress" /> <span class="ErMsg" id="ProNmMsg">Please fill out this field!</span> </div>
  81. </div>
  82. <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 form-group"> <label class="col-lg-4 col-md-4 col-sm-4 col-xs-4 cls-thought">Emergency contact
  83. <span class="red">*</span>
  84. </label>
  85. <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8"> <input class="form-control" type="text" id="txtemergency" /> <span class="ErMsg" id="ProNmMsg">Please fill out this field!</span> </div>
  86. </div>
  87. <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 form-group">
  88. <div class="col-lg-offset-7 col-lg-2 cls-divbtn "> <input class="cls-savecancel" id="btnsave" type="button" onclick="createListItem();" value="Submit" /> </div>
  89. <div class="col-lg-2 col-lg-offset-1"> <input class="cls-savecancel" type="reset" value="Cancel" id="btnCancel" data-dismiss="modal" /> </div>
  90. </div>
  91. </fieldset>
  92. </div>
  93. <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 form-group cls-sucees" style="background-color:#edeff2">
  94. <div id="successMessage"></div>
  95. </div>
  96. </div>
  97. <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 form-group LoadingDiv" id="loader" style="display:none;padding: 66px;background-color: #0a2f7d!important;">
  98. <div class="loader">Loading...</div>
  99. <div class="loader1">
  100. <p class="ones"></p>
  101. </div>
  102. </div>
  103. </div>
  104. </div>
  105. </div>
  106. <!-- update modal -->
  107. <div class="modal fade" id="ModalForUpdateEmployee" role="dialog" title="Update New Employee">
  108. <div class="modal-dialog">
  109. <fieldset>
  110. <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 cls-contriute">
  111. <h5 class="contributtitle">Update Employee Information</h5>
  112. </div>
  113. </fieldset>
  114. <div id="ModelBody">
  115. <div class="form-horizontal well bs-component cls-divthoug" id="ModalValidation">
  116. <fieldset id="bodymodal">
  117. <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 form-group"> <label class="col-lg-4 col-md-4 col-sm-4 col-xs-4 cls-thought">Employee Name
  118. <span class="red">*</span>
  119. </label>
  120. <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8"> <input class="form-control" type="text" id="txtempnames" /> <span class="ErMsg" id="ProNmMsg">Please fill out this field!</span> </div>
  121. </div>
  122. <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 form-group"> <label class="col-lg-4 col-md-4 col-sm-4 col-xs-4 cls-thought">Designation
  123. <span class="red">*</span>
  124. </label>
  125. <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8"> <input class="form-control" type="text" id="txtdesignations" /> <span class="ErMsg" id="ProNmMsg">Please fill out this field!</span> </div>
  126. </div>
  127. <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 form-group"> <label class="col-lg-4 col-md-4 col-sm-4 col-xs-4 cls-thought">Email
  128. <span class="red">*</span>
  129. </label>
  130. <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8"> <input class="form-control" type="text" id="txtemails" /> <span class="ErMsg" id="ProNmMsg">Please fill out this field!</span> </div>
  131. </div>
  132. <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 form-group"> <label class="col-lg-4 col-md-4 col-sm-4 col-xs-4 cls-thought">Mobile
  133. <span class="red">*</span>
  134. </label>
  135. <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8"> <input class="form-control" type="text" id="txtmobiles" /> <span class="ErMsg" id="ProNmMsg">Please fill out this field!</span> </div>
  136. </div>
  137. <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 form-group"> <label class="col-lg-4 col-md-4 col-sm-4 col-xs-4 cls-thought">Blood Group
  138. <span class="red">*</span>
  139. </label>
  140. <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8"> <input class="form-control" type="text" id="txtbloodgrps" /> <span class="ErMsg" id="ProNmMsg">Please fill out this field!</span> </div>
  141. </div>
  142. <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 form-group"> <label class="col-lg-4 col-md-4 col-sm-4 col-xs-4 cls-thought">Address for communication
  143. <span class="red">*</span>
  144. </label>
  145. <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8"> <input class="form-control" type="text" id="txtaddresss" /> <span class="ErMsg" id="ProNmMsg">Please fill out this field!</span> </div>
  146. </div>
  147. <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 form-group"> <label class="col-lg-4 col-md-4 col-sm-4 col-xs-4 cls-thought">Emergency contact
  148. <span class="red">*</span>
  149. </label>
  150. <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8"> <input class="form-control" type="text" id="txtemergencys" /> <span class="ErMsg" id="ProNmMsg">Please fill out this field!</span> </div>
  151. </div>
  152. <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 form-group">
  153. <div class="col-lg-offset-7 col-lg-2 cls-divbtn "> <input class="cls-savecancel" id="btnsave" type="button" onclick="update(uId);" value="Submit" /> </div>
  154. <div class="col-lg-2 col-lg-offset-1"> <input class="cls-savecancel" type="reset" value="Cancel" id="btnCancel" data-dismiss="modal" /> </div>
  155. </div>
  156. </fieldset>
  157. </div>
  158. <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 form-group cls-sucees" style="background-color:#edeff2">
  159. <div id="successMessage"></div>
  160. </div>
  161. </div>
  162. <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 form-group LoadingDiv" id="loader" style="display:none;padding: 66px;background-color: #0a2f7d!important;">
  163. <div class="loader">Loading...</div>
  164. <div class="loader1">
  165. <p class="ones"></p>
  166. </div>
  167. </div>
  168. </div>
  169. </div>
  170. </div>
  171. <!--end-->
  172. </body>
  173. </html>
Full Code

  1. $(document).ready(function() {
  2. getItems();
  3. });
  4. function createListItem() {
  5. var eName = $('#txtempname').val();
  6. var eDesg = $('#txtdesignation').val();
  7. var eEmail = $('#txtemail').val();
  8. var eMobile = $('#txtmobile').val();
  9. var eBloodGroup = $('#txtbloodgrp').val();
  10. var eComAddress = $('#txtaddress').val();
  11. var eEmergency = $('#txtemergency').val();
  12. $.ajax({
  13. async: true,
  14. url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('Employee')/items",
  15. method: "POST",
  16. data: JSON.stringify({
  17. '__metadata': {
  18. 'type': 'SP.Data.EmployeeListItem'
  19. },
  20. 'EmployeeName': eName,
  21. 'Designation': eDesg,
  22. 'Email': eEmail,
  23. 'Mobile': eMobile,
  24. 'BloodGroup': eBloodGroup,
  25. 'CommunicationAddress': eComAddress,
  26. 'EmergencyContact': eEmergency
  27. }),
  28. headers: {
  29. "accept": "application/json;odata=verbose",
  30. "content-type": "application/json;odata=verbose",
  31. "X-RequestDigest": $("#__REQUESTDIGEST").val()
  32. },
  33. success: function(data) {
  34. var eName = $('#txtempname').val("");
  35. var eDesg = $('#txtdesignation').val("");
  36. var eEmail = $('#txtemail').val("");
  37. var eMobile = $('#txtmobile').val("");
  38. var eBloodGroup = $('#txtbloodgrp').val("");
  39. var eComAddress = $('#txtaddress').val("");
  40. var eEmergency = $('#txtemergency').val("");
  41. swal("Item created successfully", "success");
  42. if ($.fn.DataTable.isDataTable('#subsiteList')) {
  43. $('#subsiteList').DataTable().destroy();
  44. }
  45. $('#subsiteList tbody').empty();
  46. getItems();
  47. },
  48. error: function(error) {
  49. console.log(JSON.stringify(error));
  50. }
  51. })
  52. }
  53. function getItems() {
  54. $.ajax({
  55. async: true,
  56. url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('Employee')/items",
  57. method: "GET",
  58. headers: {
  59. "accept": "application/json;odata=verbose",
  60. "content-type": "application/json;odata=verbose"
  61. },
  62. success: function(data) {
  63. data = data.d.results;
  64. console.log(data);
  65. $.each(data, function(index, value) {
  66. var html = "<tr><td>" + value.EmployeeName + "</td><td>" + value.Designation + "</td><td>" + value.Email + "</td><td>" + value.BloodGroup + "</td><td>" + value.CommunicationAddress + "</td><td>" + value.EmergencyContact + "</td><td>" + value.Mobile + "</td><td><a href='#' data-target='#ModalForUpdateEmployee' data-toggle='modal' onclick='edit(" + value.Id + ")'><img src='https://sharepointtechie.sharepoint.com/sites/automatedwiki/SiteAssets/CRUD/003-edit-document.png'></a></td><td><a href='#' onclick='deleteItem(" + value.Id + ");'><img src='https://sharepointtechie.sharepoint.com/sites/automatedwiki/SiteAssets/CRUD/001-delete.png'></a></td></tr>";
  67. $('.table tbody').append(html);
  68. });
  69. table = $('#subsiteList').DataTable();
  70. },
  71. error: function(error) {
  72. console.log(JSON.stringify(error));
  73. }
  74. })
  75. }
  76. function edit(value) {
  77. $.ajax({
  78. async: true,
  79. url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('Employee')/GetItemByID(" + value + ")",
  80. method: "GET",
  81. headers: {
  82. "accept": "application/json;odata=verbose",
  83. "content-type": "application/json;odata=verbose"
  84. },
  85. success: function(data) {
  86. console.log(data.d.EmployeeName);
  87. eName = $('#txtempnames').val(data.d.EmployeeName);
  88. eDesg = $('#txtdesignations').val(data.d.Designation);
  89. eEmail = $('#txtemails').val(data.d.Email);
  90. eMobile = $('#txtmobiles').val(data.d.Mobile);
  91. eBloodGroup = $('#txtbloodgrps').val(data.d.BloodGroup);
  92. eComAddress = $('#txtaddresss').val(data.d.CommunicationAddress);
  93. eEmergency = $('#txtemergencys').val(data.d.EmergencyContact);
  94. },
  95. error: function(error) {
  96. console.log(JSON.stringify(error));
  97. }
  98. })
  99. uId = value;
  100. }
  101. function update(uId) {
  102. var eName = $('#txtempnames').val();
  103. var eDesg = $('#txtdesignations').val();
  104. var eEmail = $('#txtemails').val();
  105. var eMobile = $('#txtmobiles').val();
  106. var eBloodGroup = $('#txtbloodgrps').val();
  107. var eComAddress = $('#txtaddresss').val();
  108. var eEmergency = $('#txtemergencys').val();
  109. $.ajax({
  110. url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('Employee')/items(" + uId + ")",
  111. method: "POST",
  112. data: JSON.stringify({
  113. '__metadata': {
  114. 'type': 'SP.Data.EmployeeListItem'
  115. },
  116. 'EmployeeName': eName,
  117. 'Designation': eDesg,
  118. 'Email': eEmail,
  119. 'Mobile': eMobile,
  120. 'BloodGroup': eBloodGroup,
  121. 'CommunicationAddress': eComAddress,
  122. 'EmergencyContact': eEmergency
  123. }),
  124. headers: {
  125. "accept": "application/json;odata=verbose",
  126. "content-type": "application/json;odata=verbose",
  127. "X-RequestDigest": $("#__REQUESTDIGEST").val(),
  128. "IF-MATCH": "*",
  129. "X-HTTP-Method": "MERGE"
  130. },
  131. success: function(data) {
  132. swal("Item Updated successfully", "success");
  133. if ($.fn.DataTable.isDataTable('#subsiteList')) {
  134. $('#subsiteList').DataTable().destroy();
  135. }
  136. $('#subsiteList tbody').empty();
  137. getItems();
  138. },
  139. error: function(error) {
  140. console.log(JSON.stringify(error));
  141. }
  142. })
  143. }
  144. function deleteItem(value) {
  145. $.ajax({
  146. url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('Employee')/items(" + value + ")",
  147. method: "POST",
  148. headers: {
  149. "accept": "application/json;odata=verbose",
  150. "content-type": "application/json;odata=verbose",
  151. "X-RequestDigest": $("#__REQUESTDIGEST").val(),
  152. "IF-MATCH": "*",
  153. "X-HTTP-Method": "DELETE"
  154. },
  155. success: function(data) {
  156. swal("Deleted!", "Item Deleted successfully", "success");
  157. if ($.fn.DataTable.isDataTable('#subsiteList')) {
  158. $('#subsiteList').DataTable().destroy();
  159. }
  160. $('#subsiteList tbody').empty();
  161. getItems();
  162. },
  163. error: function(error) {
  164. console.log(JSON.stringify(error));
  165. }
  166. })
  167. }
just add the content editor into the page and link the HTML file
Output
So in this article you learned how to create, read, update, delete operations using HTTP Request
Happy Sharepointing!.....