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

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

zgoforthzgoforth Posts: 167Questions: 5Answers: 0

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: 10,638Questions: 25Answers: 2,428

    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: 167Questions: 5Answers: 0

    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: 10,638Questions: 25Answers: 2,428

    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: 167Questions: 5Answers: 0

    @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: 10,638Questions: 25Answers: 2,428
    edited September 14

    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: 167Questions: 5Answers: 0

    @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: 9,822Questions: 0Answers: 1,629

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

    Colin

Sign In or Register to comment.