POST values Do not Go through to DataTable (403 Error)

POST values Do not Go through to DataTable (403 Error)

zgoforthzgoforth Posts: 493Questions: 98Answers: 2

I have created an html form to read and post data to the corresponding SharePoint list. Im positive I have the code correct, but when I execute it in SharePoint, I get a 403 error. And the JSON Object it writes doesn't appear in the console like it should. Here is my code, I don't have the proper SharePoint urls inserted because they don't work on external sources outside of SharePoint. Now I can't even get the JSON to show up in the console on the JSFiddle either

https://jsfiddle.net/p6rkmez0/

Replies

  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,951

    The 403 error is something you will need to troubleshoot on the server side. HEre is some information on the error:
    https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/403

    You will need to look at the server logs to find out why its responding with the 403 error.

    Kevin

  • zgoforthzgoforth Posts: 493Questions: 98Answers: 2

    Now I found out the issue(or at least I think I did) here, but when I click submit on the button to populate it to the DataTable, the page refreshes, which it didn't do before, and now it still gives me the
    error DevTools failed to load SourceMap: Could not load content for https://oneshellprcorp.blob.core.windows.net/oneshellpr/20200909.1/chat.map: HTTP error: status code 403, net::ERR_HTTP_RESPONSE_CODE_FAILURE

    Here is my JavaScript code

    $(document).ready(function() {
      $("#btn").click(function(e){
         var jsonData = {};
         
       var formData = $("#myform").serializeArray();
      // console.log(formData);
       
       $.each(formData, function() {
            if (jsonData[this.name]) {
               if (!jsonData[this.name].push) {
                   jsonData[this.name] = [jsonData[this.name]];
               }
               jsonData[this.name].push(this.value || '');
           } else {
               jsonData[this.name] = this.value || '';
           }
               
           
       });
       console.log(jsonData);
        jQuery.ajax({
            url: "https://site.sharepoint.com/sites/Projects/USMC/AMMO/_api/web/lists/getbytitle('AMMODeliverables')/items?$select=Program,Deliverable,To,Date,Approved,Notes",
            type: "POST",
            data:  JSON.stringify({ '__metadata': { 'type': 'SP.List' }, 'AllowContentTypes': true,
     'BaseTemplate': 100, 'ContentTypesEnabled': true, 'Description': 'My list description', 'Title': 'Test' }
    ),
            headers: {
                "accept": "application/json;odata=verbose",
                "content-type": "application/json;odata=verbose",
                "X-RequestDigest": $("#__REQUESTDIGEST").val()
            },
            success: doSuccess,
            error: doError
    });
    });
    });
    
  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,951

    DevTools failed to load SourceMap

    That is a Source Map error and is not related to your Ajax request. See this tutorial about Source Maps.

    Start by using the browsers network inspector tool to see what the request and response is.

    Kevin

  • zgoforthzgoforth Posts: 493Questions: 98Answers: 2

    @kthorngren I read the article and enabled the CSS Source Maps because some browsers don't always have it enabled. That did nothing to the populate the DataTable. It runs but just wont send my new item to the SharePoint list which would cause it to update the DataTable just like I planned

  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,951
    edited September 2020

    That did nothing to the populate the DataTable.

    Didn't expect the Source Map to fix you problem. Like I said its not related to your issue.

    It runs but just wont send my new item to the SharePoint list which would cause it to update the DataTable just like I planned

    Its hard to say what the problem would be just looking at your code snippet. Please post a link to your page or a test case replicating the issue so we can help debug.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    In fact in looking at the above code snippet I don't see anything that includes Datatables code. If your test case https://jsfiddle.net/p6rkmez0/ shows the issue please provide information of what to look at or steps to take to see the issue.

    Kevin

  • zgoforthzgoforth Posts: 493Questions: 98Answers: 2

    @kthorngren Ok, will do. https://jsbin.com/fehedigaqu/edit?html,output take a look at this one, once I submit the data, it actually shows up in the console unlike the JSFiddle I had linked. I cannot use the sharepoint urls as I am not creating the test case within SharePoint, so they are useless. Now I just need to be able to figure out this step, which is where I think the issue comes into play

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    The example doesn't contain a DataTable, so it would be worth asking on StackOverflow or a more appropriate forum,

    Colin

  • brimarwellsbrimarwells Posts: 1Questions: 0Answers: 0

    This error indicates that the server has determined that you are not allowed access to the thing you've requested, either on purpose or due to a misconfiguration . It's probably because the site owner has limited access to it and you don't have permission to view it. The vast majority of the time, there's not much you can do to fix things on your (*client) end. There are three common causes for 403 Forbidden error (server side) . Here they are listed from most likely to least likely:

    • An empty website directory
    • No index page
    • Incorrect settings in the .htaccess file
    • Permission / Ownership error

    If authentication credentials were provided in the request, the server considers them insufficient to grant access. The client SHOULD NOT automatically repeat the request with the same credentials. The client MAY repeat the request with new or different credentials. However, a request might be forbidden for reasons unrelated to the credentials.

This discussion has been closed.