0

I am having HTML file for user input and use REST API for update into SharePoint list. we have a requirement to get value from external API.

I am able run the below script from normal HTML form, and get the result

$(document).ready(function () {
    
    $("#btn_getEmpID").click(function () {
        // getUserInfo();
        // alert("vg:test ->" + localStorage.getItem("submittedID"));
        debugger;

        $.ajax({
            asynch: false,
            url:"http://dummy.restapiexample.com/api/v1/employees",
            method: "GET",
            headers: {
                "Accept": "application/json; odata=verbose"
            },
            success: function (data) {
                debugger;
                alert("test:SUCCESS");
            },
            error: function (x, y, z) {
                debugger;
                alert(JSON.stringify(x) + '\n' + JSON.stringify(y) + '\n' + JSON.stringify(z));
            }
        });
    });
})  

while using in SharePoint online, I am getting error.

What would be the best option to access the external API in SharePoint online page?

thanks GV

  • I have used this HTML form as a page in SharePoint to enter input and submit the data into SharePoint list. – AVG Aug 20 at 9:27
  • What exactly is the error that you are getting? – Dylan Cristy Aug 20 at 13:59
0

If we call this rest api directly,it reports this error. enter image description here Soluation:

https://developer.mozilla.org/en-US/docs/Web/Security/Mixed_content/How_to_fix_website_with_mixed_content Updated code:

<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script>

$(document).ready(function () {                  
        $.ajax({                
            url:"https://dummy.restapiexample.com/api/v1/employees",
            method: "GET",
            headers: {
                "Accept": "application/json; odata=verbose"
            },
            success: function (data) {                    
                console.log(data);
            },
            error: function (error) {                    
                console.log(error);
            }
        
    });
})  
</script>

Test Result: enter image description here

| improve this answer | |

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.