Connect AngularJS to SharePoint 2010 List

2019-08-02 04:15发布

I'm trying to connect my AngularJS App to a Sharepoint 2010 List.

I've tried this and this tutorial but neither work for me. Those 2 tutorials are using SharePoint 2013.

Well the first question is: "Does SharePoint 2010 have a RestAPI for me to connect with?" - If SP 2010 has this feature, why can't I connect with the list?

My list is called "Steckbrief_Data" and the code I'm trying to run is:

var app = angular.module('myApp', []); 
app.controller('myCtrl', function($scope, $http) {
        $http(
        {
            method: "GET",
            url: GetSiteUrl() + "_api/web/lists/getByTitle('Steckbrief_Data')/items"
            headers: {"Accept": "application/json;odata=verbose" }
        }).success(function (data, status, headers, config) {
            alert("success");
            $scope.Employees = data.d.results;
        }).error(function (data, status, headers, config) {
            alert("error");
        });
    }); 

function GetSiteUrl() {
    var urlParts = document.location.href.split("/");
    return urlParts[0] + "//" + urlParts[2] + "/" + urlParts[3] + "/" + urlParts[4];
}   

So could you tell me what is going wrong here?

Thanks and greetings, Michael

1条回答
时光不老,我们不散
2楼-- · 2019-08-02 04:24

SharePoint 2010 has a REST API, but it isn't as extensive as 2013's. In your case, 'getByTitle' is not part of the 2010 API.

In the 2010 API, to get list data, your URL might be something like:

http://yourserver/yoursite/_vti_bin/ListData.svc/Steckbrief_Data

Where Steckbrief_Data is the list whose data you want and http://yourserver/yoursite/ is the path to the site where the list resides.

If this doesn't work off the bat, in a browser, try http://yoursever/yoursite/_vti_bin/ListData.svc/ first. Get the internal name of the list and try that in place of Steckbrief_Data

Read more detailed information here

查看更多
登录 后发表回答