0

Hi I am trying to insert a list item in a SharePoint list by using REST api. I am getting an error as:

{
    "readyState": 4,
    "responseText": "{\"error\":{\"code\":\"-2130575251, Microsoft.SharePoint.SPException\",\"message\":{\"lang\":\"en-US\",\"value\":\"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.\"}}}",
    "responseJSON": {
        "error": {
            "code": "-2130575251, Microsoft.SharePoint.SPException",
            "message": {
                "lang": "en-US",
                "value": "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."
            }
        }
    },
    "status": 403,
    "statusText": "FORBIDDEN"
}

I used the following code:

function addData() {

    var listUrl = "/_api/Web/Lists/GetByTitle('QuestionsList')/Items";

    var studID = $("#stID").val();
    var optionVal = $(".rdBtn").val();

    alert(listUrl);

    $.ajax({
        url: "http://myserverAndSiteName" + listUrl,

        type: "POST",
        contentType: "application/json;odata=verbose",
        data: JSON.stringify({
            __metadata: {
                type: "SP.Data.StudentResponseListItem"
            },
            StudentID: $("#stID").val(),
            QuestionNumber: qno,
            Question: question,
            StudentAnswer: $(".rdBtn").val()
        }),
        headers: {
            "Accept": "application/json;odata=verbose", // return data format  
            "X-RequestDigest": $("#__REQUESTDIGEST").val()
        },
        success: function(data) {
            $("#tblEmployees").empty();
            getItem(listUrl);
            alert("Successfully Submitted");
        },
        error: function(error) {
            alert(JSON.stringify(error));
        }
    });
}
  • 1
    I suggest to check digest, are you sure that you are retrieving it correctly? – RiccardoGDev Mar 31 at 14:25
  • 1
    As suggested by @RiccardoGDev, make sure that your request digest value is not empty. If it is empty/null, you can make a POST request to "YourwebURL/_api/contextinfo" and get the request digest value. And then Use this rewuest digest value in your subsequent request. – Rohit Waghela Apr 2 at 11:09
  • The digest is correct. Actually, the target list name was in correct and I forgot to write ListItem after the list name in the " type: "SP.Data........" attribute. Thank you all for your suggestions. – Purushottam Patil Apr 5 at 5:15
0
  1. open an elevated command prompt:

    a) Go to start and type in cmd in the search box.

    b) Right click on the command prompt and click run as administrator.

  2. Now reset your TCP/IP stack:

    a) Type the following commands (see below) in the command prompt, each followed by pressing enter.

    b) Restart the computer.

  3. Now open Internet Explorer and check if you can access the website.

ipconfig /flushdns
nbtstat -R
nbtstat -RR
netsh int reset all
netsh int ip reset
netsh winsock reset
Exit
  • Thank you for your suggestion. Actually, the target list name was in correct and I forgot to write ListItem after the list name in the " type: "SP.Data........" attribute. – Purushottam Patil Apr 5 at 5:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.