I am making a POST request to Sharepoint List and in that I have to add items more than 150 which takes my like 45-50 mins to add all the Line details. And once I have added I click on submit and then I got to network tab i see error. Below is my code for adding those 150 items.
if ($("#tbodyRAssetMaterial")[0].children.length > 0) {
for (i = 0; i < $("#tbodyRAssetMaterial")[0].children.length; i++) {
RSrNo = $("#lblRSrNo" + itemCount).text();
RAssetNo = $("#txtRAssetNo" + itemCount).val();
RDescriptionOfItems = $("#txtRDescriptionOfItems" + itemCount).val();
RQuantity = $("#txtRQuantity" + itemCount).val();
RUnit = $("#txtRUnit" + itemCount).val();
RDateOfReturn = moment($("#dtRDateOfReturn" + itemCount).val()).format(
"YYYY-MM-DD"
);
RRemarks = $("#txtRRemarks" + itemCount).val();
var quantity = 0;
sumOfTotalQuantity = parseFloat(sumOfTotalQuantity) + parseFloat(RQuantity);
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl +
"/_api/web/lists/GetByTitle('ASMGP')/items",
type: "POST",
data: JSON.stringify({
__metadata: {
type: GetItemTypeForListName("ASMGP"),
},
Title: RSrNo,
AssetNo: RAssetNo,
DescriptionOfItems: RDescriptionOfItems,
Quantity: RQuantity,
Unit: RUnit,
ExpectedDateOfReturn: RDateOfReturn,
GatePassMasterID: itemId.toString(),
GatePassIdId: itemId,
Remarks: RRemarks,
}),
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) {
alert("Your Gatepass Created Successfully. Serial No.: " + NewSrNo);
},
error: function(xhr, status, error) {
//$(".page-loader").addClass("d-none");
},
});
itemCount++;
}
UpdateSumOfTotalQuantity(itemId, sumOfTotalQuantity, NewSrNo);
}
}
the security validation for this page is invalid and might be corrupted. Please use your web browser's Back button to try your operation again.
As per google's suggestion i have also added "X-RequestDigest": $("#__REQUESTDIGEST").val(), in Headers section, still Im unable to to do the POST request. Im trying on SharePoint Online. Please help, any suggestion will be appreciated.!!!