none
Security validation error rest api :The security validation for this page is invalid and might be corrupted RRS feed

  • Question

  • Security validation error rest api post

    Error:The security validation for this page is invalid and might be corrupted

    Below is my code

     function CreateEvenCabRequest(){
                Contact= $("#ContacNo").html();
                    City= $("#City").html();
                    
       
    $.ajax  
            ({  
            url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('Request')/items",  
            type: "POST",  
            data: JSON.stringify  
            ({  
                __metadata:  
                {  
                    type: "SP.Data.RequestListItem"  
                },  
                ContactNo: Contact,  
                City: City,  
             
            }),  
            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)  
            {  
                    swal("Successfully Initiated", "Your request has been generated!", "success", {
      button: "ok",
    //  window.location.reload(),
    }).then(function() {

    });

     
            },  
            error: function(xhr, status, error)  
            { 
                    console.log(xhr.responseText);
    swal("Some Error occured,refresh the page if still facing issue Contact IT Team.");
     
            }  
        });  
    }  


    Shiv Sharma




    Friday, July 3, 2020 9:51 AM

All replies

  • Hi SharePoint User02,

    This error seems to be related to incorrect digest. Could you please have a try following approaches:

    1. Make sure the control "__REQUESTDIGEST" is already rendered before calling the request
    2. Sometimes the digest may be expired, hence please full refresh the page or get digest from "_api/contextinfo"

    Best Regards,

    Baker Kong


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click  here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.


    Monday, July 6, 2020 5:21 AM
  • Please tell me where to put this _api/contextinfo...

    Kindly update in my code. then i will check is it working find or not


    Shiv Sharma

    Tuesday, July 7, 2020 8:30 AM
  • Hi SharePoint User02,

    _api/contextinfo is an endpoint. You can retrieval digest from this endpoint.

    Thanks

    Baker Kong


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click  here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Tuesday, July 7, 2020 9:55 AM
  • Kindy Update in my code

    Shiv Sharma

    Wednesday, July 8, 2020 2:44 PM