Search code examples
ajaxweb-servicessharepointgetsharepoint-clientobject

Sharepoint How to do get request to external web service


How can I make get request from Sharepoint object model to external web service? I tried did it with ajax request:

 $.get("http:/servername/webservice_name", function(data, status) {
alert("Data: " + data[0] + "\nStatus: " + status);

});

But I have an error: Access denied. My web service has response in JSON format. I have read a lot of article, but there are no decisions. I read, that ajax forbidden in SharePoint for external web service. How can I make it without ajax?


Solution

  • In the SharePoint online it is work only for https web services. http from https web sites not allowed. Final code, which work with https:

    $(document).ready(function(){
    $.ajax({
        url: "https://services.odata.org/Northwind/Northwind.svc/Customers",
        type: "GET",
        headers: { "ACCEPT": "application/json;odata=verbose" },
        async: false,
        success: function (data) {
            if(data.d.results.length>0){
                alert("Results Count:"+data.d.results.length);
            }else{
                alert("no data");
            }
        },
        error: function () {
            //alert("Failed to get details");                
        }
    });
    

    });