ochojoneso
1/14/2019 - 3:33 PM

Ajax Create List Item

      // CREATE Operation
      // listName: The name of the list you want to get items from
      // weburl: The url of the web that the list is in.
      // newItemTitle: New Item title.
      // success: The function to execute if the call is sucesfull
      // failure: The function to execute if the call fails
      function CreateListItemWithDetails(listName, webUrl, newItemTitle, success, failure) {
          var itemType = GetItemTypeForListName(listName);
          var item = {
              "__metadata": { "type": itemType },
              "Title": newItemTitle,
      
          };
      
          $.ajax({
              url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/lists/getbytitle('" + listName + "')/items",
              type: "POST",
              contentType: "application/json;odata=verbose",
              data: JSON.stringify(item),
              headers: {
                  "Accept": "application/json;odata=verbose",
                  "X-RequestDigest": $("#__REQUESTDIGEST").val()
              },
              success: function (data) {
                  success(data);
              },
              error: function (data) {
                  failure(data);
              }
          });
      }